You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running "String matching" consisting of 2 tests, 100,000 iterations...
Values that fall outside of 3 standard deviations of the mean are discarded.
For preg_match out of 98,997 runs, average time was 0.0000118057 seconds.
For strpos out of 99,871 runs, average time was 0.0000104146 seconds.
Results:
Test Name Time + Interval Change
strpos 0.0000104146 +0.0000000000 baseline
preg_match 0.0000118057 +0.0000013912 13% slower
Installation
The recommended way to install Nice Bench is through Composer. Just run the
php composer.phar require command in your project directory to install it:
php composer.phar require nice/bench:~1.0
Usage
Create a file called tests.php in your project directory, and add:
<?phprequire__DIR__ . '/vendor/autoload.php';
useNice\Benchmark\Benchmark;
$arr = range(1, 10000);
$benchmark = newBenchmark(10000, 'foreach');
$benchmark->register('foreach with value', function() use ($arr) {
foreach ($arras$value) {
}
});
$benchmark->register('foreach with key, value', function() use ($arr) {
foreach ($arras$key => $value) {
}
});
$benchmark->execute();
Then run tests.php in your terminal:
$ php tests.php
Running "foreach" consisting of 2 tests, 10,000 iterations...
Values that fall outside of 3 standard deviations of the mean are discarded.
For foreach with value out of 9,871 runs, average time was 0.0011523914 seconds.
For foreach with key, value out of 9,874 runs, average time was 0.0016814657 seconds.
Results:
Test Name Time + Interval Change
foreach with value 0.0011523914 +0.0000000000 baseline
foreach with key, value 0.0016814657 +0.0005290744 46% slower