Replies: 1 comment 1 reply
-
|
Hello, I created some benchmark to check this. <?php
/*
* This file is part of Chevere.
*
* (c) Rodolfo Berrios <rodolfo@chevere.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chevere\Tests\Benchmark;
use Chevere\Parameter\IntParameter;
use LogicException;
use function Chevere\Parameter\int;
$intParameter = int(min: 2);
class TimeConsumerBench
{
/**
* @Revs(1000)
* @Iterations(5)
*/
public function benchConsumeNative()
{
benchNative(10);
}
/**
* @Revs(1000)
* @Iterations(5)
*/
public function benchConsumeInt()
{
benchInt(10);
}
/**
* @Revs(1000)
* @Iterations(5)
*/
public function benchConsumeIntCached()
{
global $intParameter;
benchIntCached($intParameter, 10);
}
}
function benchNative(int $int): int
{
return $int > 1
? $int
: throw new LogicException();
}
function benchInt(int $int): int
{
return int(min: 2)($int);
}
function benchIntCached(IntParameter $parameter, int $int): int
{
return $parameter($int);
}Of course, it adds some time. But you can cache your parameters in case you want faster performance. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
The package aspect-oriented concept is interesting. Have you conducted any benchmarks comparing it to usual inline validation?
Beta Was this translation helpful? Give feedback.
All reactions