$string = str_repeat("a", $n); return function () use($string) { return strtolower($string); }; }, true)->registerFunctional('mb_strtolower', 'mb_strtolower', function ($n) { $string = str_repeat("a", $n); return function () use($string) { return mb_strtolower($string); }; }, true); $bench->benchmark(1000, 64); $bench->benchmark(1000, 128); $bench->benchmark(1000, 256); //var_dump($bench->getResults()); $groups = array($bench->getResults()); $bench = new \Nicmart\Benchmark\VariabeSizeEngine('Cycles'); $bench->registerFunctional('logarithmic', 'Logarithmic', function ($n) { return function () use($n) { for ($i = 1; $i <= $n; $i *= 2) { } }; }, false, function ($n) { return log($n, 2) * 3; })->registerFunctional('linear', 'Linear', function ($n) { return function () use($n) { for ($i = 0; $i < $n; $i++) { } }; }, true)->registerFunctional('square', 'Square', function ($n) { return function () use($n) { for ($i = 0; $i < $n; $i++) {
for ($i = 0; $i < $n; $i++) { $ary[$i] = null; } }; }, true)->registerFunctional('splfixed', 'SplFixedArray', function ($n) { return function () use($n) { $ary = new SplFixedArray($n); for ($i = 0; $i < $n; $i++) { $ary[$i] = null; } }; }, true); //$bench->benchmark(10000, 100); $bench->progression(10000, 400, 2); $groups[] = $bench->getResults(); $bench = new \Nicmart\Benchmark\VariabeSizeEngine('Array versus SplFixedArray - Access items'); $bench->registerFunctional('array', 'array', function ($n) { $ary = array(); for ($i = 0; $i < $n; $i++) { $ary[$i] = $i; } return function () use($ary) { for ($i = 0; $i < count($ary); $i++) { $j = $ary[$i]; } }; }, true)->registerFunctional('splfixed', 'SplFixedArray', function ($n) { $ary = new SplFixedArray($n); return function () use($ary) { for ($i = 0; $i < count($ary); $i++) { $j = $ary[$i];
<?php /** * This file is part of Benchmark * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @author Nicolò Martini <*****@*****.**> */ include '../vendor/autoload.php'; $groups = array(); $bench = new \Nicmart\Benchmark\VariabeSizeEngine('String interpolation vs concatenation'); $bench->registerFunctional('interpolation', 'Interpolation', function ($n) { $a = $b = str_repeat('x', $n); return function () use($a, $b) { return "xxx {$a}{$b} xxx"; }; }, true)->registerFunctional('concatenation', 'Concatenation', function ($n) { $a = $b = str_repeat('x', $n); return function () use($a, $b) { return "xxx" . $a . $b . " xxx"; }; }, true)->registerFunctional('sprintf', 'Sprintf', function ($n) { $a = $b = str_repeat('x', $n); return function () use($a, $b) { return sprintf("xxx %s%s xxx", $a, $b); }; }, true); //$bench->benchmark(10000, 100); $bench->progression(1000, 8, 4);