function benchmark_many($iterations = 10) { $res = ['json' => 0, 'yaml' => 0]; for ($i = 0; $i < $iterations; ++$i) { $stats = benchmark(generate_complex_array()); $res['json'] += $stats['json']; $res['yaml'] += $stats['yaml']; } $res['json'] /= $iterations; $res['yaml'] /= $iterations; return $res; }
function benchmark(Benchmark $benchmark, array $configs, &$result) { global $recursion; $benchmarkCase = getenv('BENCHMARK_CASE') ?: null; foreach ($configs as $case => $config) { if ($benchmarkCase === $case || null === $benchmarkCase) { try { $result[] = $benchmark->run($config); } catch (\Doctrine\DBAL\Exception\ConnectionException $ex) { if ($recursion > 10) { throw $ex; } $recursion++; trigger_error($ex->getMessage(), E_USER_NOTICE); trigger_error("Waiting for database ...", E_USER_NOTICE); sleep(10); benchmark($benchmark, $configs, $result); } } } }
* @param $ary * @param array $keyStack */ $iterateWithoutIterator = function (&$ary, $keyStack = array()) { global $iterateWithoutIterator; $keyValues = array(); foreach ($ary as $key => $value) { if (!is_array($value)) { $nestedKey = implode('.', array_merge($keyStack, array($key))); $keyValues[$nestedKey] = $value; } else { $keyStack2 = $keyStack; $keyStack2[] = $key; $keyValues = array_merge($keyValues, $iterateWithoutIterator($value, $keyStack2)); } } }; function benchmark($f, $ary, $title = '', $iterations = 10000) { echo '<br><b>', $title, '</b><br>'; $start = microtime(true); for ($i = 0; $i < $iterations; $i++) { $f($ary); } $time = microtime(true) - $start; echo 'Time: ', $time, '<br>'; echo 'Average: ', $time / $iterations, '<br>'; } benchmark($iterateWithIterator, $ary, 'With Iterator'); benchmark($iterateWithoutIterator, $ary, 'Without Iterator');
end ENDIR; /** * Compile the function using the JITFU extension! * * This is extremely cheap, since no analysis needs to happen. All that happens is the IR * is turned into JIT-Fu instructions (which are then compiled by libjit). */ $func = Jit::getInstance()->compileIrJitFu($ir, 'fibo'); /** * Now let's benchmark the two implementations! * * If you don't have JitFu installed, then both should be equal. */ benchmark("fibo", "PHP"); benchmark($func, "ReckiCT"); /** * A very light weight benchmark tool, which runs the code 100,000 times. * * @param callable $func The function to benchmark * @param string $label The label of the test, for output * * @return void */ function benchmark(callable $func, $label) { $start = microtime(true); $result = $func(30); $end = microtime(true); printf("%s completed fibo(30)=={$result} in %01.4F seconds\n", $label, $end - $start); }
<?php require 'vendor/autoload.php'; function benchmark($name, $runs, $function) { $start = microtime(true); while ($runs--) { $function(); } $end = microtime(true); return sprintf('%s: %s', $name, $end - $start) . PHP_EOL; } function heavyCalc($varA, $varB) { usleep(100); return $varA + $varB; } $memoized = Knlv\memoize('heavyCalc'); echo benchmark('heavyCalc(1, 2)', 100, function () { heavyCalc(1, 2); }); echo benchmark('Memoized heavyCalc(1, 2)', 100, function () use(&$memoized) { $memoized(1, 2); });
benchmark('invoke', $array, $iterator, $hash, $hashIterator, 'method'); benchmark('last', $array, $iterator, $hash, $hashIterator, function ($v, $k) { return $v > 1000; }); benchmark('map', $array, $iterator, $hash, $hashIterator); benchmark('none', $array, $iterator, $hash, $hashIterator); benchmark('partition', $array, $iterator, $hash, $hashIterator, function ($v, $k) { return $v / 2; }); benchmark('pluck', $array, $iterator, $hash, $hashIterator, 'property'); benchmark('product', $array, $iterator, $hash, $hashIterator, false); benchmark('ratio', $array, $iterator, $hash, $hashIterator, false); benchmark('reduce_left', $array, $iterator, $hash, $hashIterator, function ($v) { return $v; }); benchmark('reduce_right', $array, $iterator, $hash, $hashIterator, function ($v) { return $v; }); benchmark('reject', $array, $iterator, $hash, $hashIterator); benchmark('select', $array, $iterator, $hash, $hashIterator); benchmark('some', $array, $iterator, $hash, $hashIterator); benchmark('sum', $array, $iterator, $hash, $hashIterator, false); benchmark('difference', $array, $iterator, $hash, $hashIterator, false); benchmark('ratio', $array, $iterator, $hash, $hashIterator, false); benchmark('product', $array, $iterator, $hash, $hashIterator, false); benchmark('average', $array, $iterator, $hash, $hashIterator, false); benchmark('first_index_of', $array, $iterator, $hash, $hashIterator, 2000); benchmark('last_index_of', $array, $iterator, $hash, $hashIterator, 2000); benchmark('head', $array, $iterator, $hash, $hashIterator); benchmark('tail', $array, $iterator, $hash, $hashIterator);
function html_my_layout($vars){ extract($vars);?> <html> <head> <title>Limonde second example</title> </head> <body> <h1>Limonde second example: errors</h1> <?php echo $content?> <hr> <p> <a href="<?php echo url_for('/')?>">Home</a> | <a href="<?php echo url_for('/everything/is_going_wrong')?>">everything is going wrong</a> | <a href="<?php echo url_for('/welcome/')?>">Welcome !</a> | <a href="<?php echo url_for('/welcome/bill')?>">Welcome Bill ?</a> | <a href="<?php echo url_for('/welcome/leland')?>">Welcome Leland ?</a> | <a href="<?php echo url_for('/welcome/bob')?>">Welcome Bob ?</a> | <a href="<?php echo url_for('/welcome/david')?>">Welcome David ?</a> | <a href="<?php echo url_for('/welcome/audrey')?>">Welcome Audrey ?</a> | </p> </body> </html> <!-- <?php print_r(benchmark()); ?> --> <?};
// Determine the average runtime across all trials. foreach ($results['t'] as &$result) { $result /= TRIALS; } return $results; } $results = []; echo "Generating benchmarks...\n"; // Run each benchmark in the schedule. foreach ($schedule as $name => $batches) { $results[$name] = $results[$name] ?? []; foreach ($batches as $batchId => $batch) { $results[$name][$batchId] = []; list($range, $candidates) = $batch; if (count($candidates) === 0) { continue; } echo "\n\t{$name}:"; foreach ($candidates as $candidate) { echo "\n\t\t{$candidate} "; list($type, $functions) = $config[$name]; $functions = $functions[$candidate]; // Benchmark this task according to its setup, tick and reset functions. $results[$name][$batchId][$candidate] = benchmark($type, $range, ...$functions); } echo "\n"; } } // This will be the path that the reporter will use. $results_path = __DIR__ . '/results.json'; file_put_contents($results_path, json_encode($results, JSON_PRETTY_PRINT));
<?php require_once __DIR__ . '/common.php'; $num = isset($argv[1]) ? $argv[1] : 1000; printf("creating %d test domain objects\n", $num); benchmark($num, function () { $rel = new TestRelationship(); $object = new TestObject(); $object->TestRel = $rel; $rel->save(); $object->save(); });
foreach ($args as $arg) { $total += $arg; $count++; } return $total / $count; } function average2(...$args) { $total = 0; $count = 0; foreach ($args as $arg) { $total += $arg; $count++; } return $total / $count; } $arr = [1, 2, 3, 4, 5]; echo "Step1. func_get_args() vs ... \n"; echo benchmark(function () { average1(1, 2, 3, 4, 5); }, 10000), "\n"; echo benchmark(function () { average2(1, 2, 3, 4, 5); }, 10000), "\n"; echo "Step2. call_user_func_array() vs ... \n"; echo benchmark(function () use($arr) { call_user_func_array('average2', $arr); }, 10000), "\n"; echo benchmark(function () use($arr) { average2(...$arr); }, 10000), "\n";
function on_exit() { execute_hook('content_end'); benchmark('Everything Done. Will send output to template.php'); benchmark(NULL, true); $ctrl = global_var('controller'); while ($ctrl !== false) { $ctrl = substr($ctrl, 0, strrpos($ctrl, '/')); $template = config('base_path') . 'app/' . $ctrl . '/_template.php'; if (file_exists($template)) { global_var('template_file', $template, 1); include $template; break; } } if (!isset($_SESSION['new_flash'])) { $_SESSION['new_flash'] = array(); } $_SESSION['flash'] = $_SESSION['new_flash']; unset($_SESSION['new_flash']); execute_hook('exit'); }
$collection = array(); for ($i = 0; $i < 50; $i++) { $collection[] = createObject(); } return $collection; } function createObject() { $post = new \JMS\Serializer\Tests\Fixtures\BlogPost('FooooooooooooooooooooooBAR', new \JMS\Serializer\Tests\Fixtures\Author('Foo'), new \DateTime()); for ($i = 0; $i < 10; $i++) { $post->addComment(new \JMS\Serializer\Tests\Fixtures\Comment(new \JMS\Serializer\Tests\Fixtures\Author('foo'), 'foobar')); } return $post; } $serializer = \JMS\Serializer\SerializerBuilder::create()->build(); $collection = createCollection(); $metrics = array(); $f = function () use($serializer, $collection, $format) { $serializer->serialize($collection, $format); }; // Load all necessary classes into memory. benchmark($f, 1); printf('Benchmarking collection for format "%s".' . PHP_EOL, $format); $metrics['benchmark-collection-' . $format] = benchmark($f, $iterations); $output = json_encode(array('metrics' => $metrics)); if (isset($_SERVER['argv'][3])) { file_put_contents($_SERVER['argv'][3], $output); echo "Done." . PHP_EOL; } else { echo $output . PHP_EOL; }
<?php require_once __DIR__ . '/common.php'; $num = isset($argv[1]) ? $argv[1] : 10000; $binder = new \Pheasant\Database\Binder(); $binds = array(array('SELECT * FROM table WHERE column=?', array('test')), array('x=?', array('10\'; DROP TABLE --')), array('column1=? and column2=?', array(false, true)), array("name='???' and llamas=?", array(24)), array("name='\\'7r' and llamas=?", array(24)), array("name='\\'7r\\\\' and another='test question?' and llamas=?", array(24)), array("name='\\'7r\\\\' and x='\\'7r' and llamas=?", array(24))); printf("binding %d statements %d times\n", count($binds), $num); benchmark($num, function () use($binds, $binder) { foreach ($binds as $bind) { $binder->bind($bind[0], $bind[1]); } });
} return $post; } $serializer = \Kcs\Serializer\SerializerBuilder::create()->setEventDispatcher(new \Symfony\Component\EventDispatcher\EventDispatcher())->build(); $collection = createCollection(); $metrics = []; $f = function ($format) use($serializer, $collection) { $serializer->serialize($collection, $format); }; // Load all necessary classes into memory. $f('array'); $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(['Format', 'Direction', 'Time']); $progressBar = new \Symfony\Component\Console\Helper\ProgressBar($output, 8); $progressBar->start(); foreach (['array', 'json', 'yml', 'xml'] as $format) { $table->addRow([$format, 'serialize', benchmark($f, $format)]); $progressBar->advance(); } $serialized = ['array' => $serializer->serialize($collection, 'array'), 'json' => $serializer->serialize($collection, 'json'), 'yml' => $serializer->serialize($collection, 'yml'), 'xml' => $serializer->serialize($collection, 'xml')]; $type = new \Kcs\Serializer\Type\Type('array', [\Kcs\Serializer\Type\Type::from(\Kcs\Serializer\Tests\Fixtures\BlogPost::class)]); $d = function ($format) use($serializer, $serialized, $type) { $serializer->deserialize($serialized[$format], $type, $format); }; foreach (['array', 'json', 'yml', 'xml'] as $format) { $table->addRow([$format, 'deserialize', benchmark($d, $format)]); $progressBar->advance(); } $progressBar->finish(); $progressBar->clear(); $table->render();
} $file = $argv[1]; $extension = strtolower(substr($file, strrpos($file, '.') + 1)); $out = tempnam($config['tmp'], 'thumb'); $count = 300; function benchmark($method) { global $config, $file, $extension, $out, $count; $config['thumb_method'] = $method; printf("Method: %s\nThumbnailing %d times... ", $method, $count); $start = microtime(true); for ($i = 0; $i < $count; $i++) { $image = new Image($file, $extension); $thumb = $image->resize($config['thumb_ext'] ? $config['thumb_ext'] : $extension, $config['thumb_width'], $config['thumb_height']); $thumb->to($out); $thumb->_destroy(); $image->destroy(); } $end = microtime(true); printf("Took %.2f seconds (%.2f/second; %.2f ms)\n", $end - $start, $rate = $count / ($end - $start), 1000 / $rate); unlink($out); } benchmark('gd'); if (extension_loaded('imagick')) { benchmark('imagick'); } else { echo "Imagick extension not loaded... skipping.\n"; } benchmark('convert'); benchmark('gm'); becnhmark('convert+gifsicle');
call_user_func_array('sprintf', $args); }; $varsSearch = array('foo', 'baz', 'goo.a', 'goo.c'); $varsReplace = array('bar', 'friend', 'b', 'd'); $strReplace = function () use($template, $varsSearch, $varsReplace) { str_replace($varsSearch, $varsReplace, $template); }; function benchmark($f, $title = '', $iterations = 100000) { static $firstTime = 0; echo '<br><b>', $title, '</b><br>'; $start = microtime(true); for ($i = 0; $i < $iterations; $i++) { $f(); } $time = microtime(true) - $start; echo 'Time: ', $time, '<br>'; if ($firstTime) { echo 'Factor: ', sprintf("%d.3×", $time / $firstTime); echo ', Reverse Factor: ', sprintf("%d.3×", $firstTime / $time), '<br>'; } else { $firstTime = $time; } echo 'Average: ', $time / $iterations, '<br>'; echo 'MemoryPeak: ', memory_get_peak_usage(), ' (meaningful only if you run one benchmark at time)'; } benchmark($replace, 'Engine benchmark'); benchmark($replaceSprintf, 'Engine Sprintf benchmark'); benchmark($sprintf, 'Sprintf benchmark'); benchmark($strReplace, 'StrReplace benchmark');
benchmark($numIterations, $fastQueue); $times['fast'] = microtime(true) - $start; $start = microtime(true); $zendSplQueue = new ZendSplPriorityQueue(); benchmark($numIterations, $zendSplQueue); $times['zend_spl'] = microtime(true) - $start; $start = microtime(true); $zendPriorityQueue = new ZendPriorityQueue(); benchmark($numIterations, $zendPriorityQueue); $times['zend_priority'] = microtime(true) - $start; print_results($times); printf("\n--- Benchmark %s insert and extract with random priority (1,100)\n", number_format($numIterations)); $times = []; $start = microtime(true); $splQueue = new \SplPriorityQueue(); benchmark($numIterations, $splQueue); $times['spl'] = microtime(true) - $start; $start = microtime(true); $fastQueue = new FastPriorityQueue(); benchmark_random($numIterations, $fastQueue); $times['fast'] = microtime(true) - $start; $start = microtime(true); $zendSplQueue = new ZendSplPriorityQueue(); benchmark_random($numIterations, $zendSplQueue); $times['zend_spl'] = microtime(true) - $start; $start = microtime(true); $zendPriorityQueue = new ZendPriorityQueue(); benchmark_random($numIterations, $zendPriorityQueue); $times['zend_priority'] = microtime(true) - $start; print_results($times); printf("\n* The PHP SplPriorityQueue with the order issue (https://bugs.php.net/bug.php?id=60926)\n");
return $fileData; } $dir = 'core/getFromFile'; $files = array("{$dir}/huge.csv", "{$dir}/prettyBig.csv", "{$dir}/big.csv", "{$dir}/small.csv"); $missingFiles = array(); foreach ($files as $file) { if (!is_file($file)) { $missingFiles[] = $file; } } if ($missingFiles !== array()) { $errMsg = 'Error: this test requires certain files to exist:'; foreach ($files as $file) { $errMsg .= '<br>' . $file; } $errMsg .= '<br><br>You are missing:'; foreach ($missingFiles as $file) { $errMsg .= '<br>' . $file; } exit($errMsg); } $functions = array('without_array_combine', 'with_array_combine'); $iterations = 15; $times = array(); foreach ($files as $file) { $args = array($file); foreach ($functions as $func) { $times[$file][$func] = benchmark($func, $iterations, $args); } } var_dump($times);
$cell = trim($cell); } return $line; } function trimIndex($line) { foreach ($line as $i => $cell) { $line[$i] = trim($cell); } return $line; } function createRow($line) { $row = array(); foreach ($line as $cell) { $row[] = trim($cell); } return $row; } $line = range('a', 'c'); $line = array(' hfhfuishgsfgd', 'sdifgnisfng sfgnsdfg', ' fgsfg sfgsfgius ', ' ifgisdfgnisdnfginsdfi sfign sfg '); $iterations = 501; echo benchmark('trimRef', $iterations, array($line)) . '<br>'; echo benchmark('trimIndex', $iterations, array($line)) . '<br>'; echo benchmark('createRow', $iterations, array($line)) . '<br>'; echo '<br>'; $line = range('a', 'z'); echo benchmark('trimRef', $iterations, array($line)) . '<br>'; echo benchmark('trimIndex', $iterations, array($line)) . '<br>'; echo benchmark('createRow', $iterations, array($line)) . '<br>';
$startTime = microtime(true); for ($i = 0; $i < $loops; $i++) { $op(); } return (microtime(true) - $startTime) / $loops; } $ops = array('Reading a file' => function () use($file) { file_get_contents($file); }, 'Calling stat()' => function () use($file) { stat($file); }, 'Reading a directory' => function () use($file) { $dir = opendir(dirname($file)); $list = array(); while (($file = readdir($dir)) !== false) { $list[] = $file; } closedir($dir); }); $results = 'Operation;Native wrapper;php-wrapper' . "\n"; foreach ($ops as $opTitle => $op) { // Using the native wrapper $native = benchmark($op, $loops); echo $opTitle . ' with native wrapper: ' . $native . ' s/op' . PHP_EOL; // Using php-wrappers Wrappers\FtpStream::register(); $wrappers = benchmark($op, $loops); echo $opTitle . ' with php-wrappers: ' . $wrappers . ' s/op' . PHP_EOL; Wrappers\FtpStream::unregister(); $results .= $opTitle . ';' . $native . ';' . $wrappers . "\n"; } file_put_contents(__DIR__ . '/benchmark-results.csv', $results);
function test_main_benchmark() { $bench = benchmark(); assert_true(is_array($bench)); assert_true(array_key_exists('execution_time', $bench)); if (function_exists('memory_get_usage')) { assert_true(defined('LIM_START_MEMORY')); assert_true(array_key_exists('start_memory', $bench)); assert_equal(LIM_START_MEMORY, $bench['start_memory']); } }
<?php function simpleFunc() { $test = 1 + 1; } $iterations = 10000; $start = microtime(true); for ($i = 0; $i < $iterations; ++$i) { simpleFunc(); } $t1 = microtime(true) - $start; $t2 = benchmark('simpleFunc', $iterations); echo 't1: ' . $t1 . '<br>'; echo 't2: ' . $t2 . '<br>'; echo '<br>t3: ' . ($t2 - $t1);
<?php $files = array('core/arrayToLine/benchmark.csv', 'core/arrayToLine/benchmark2.csv'); $args = array(array('Username' => 'Participant001', 'ID' => 'aaaaaaaa', 'Condition' => 'control', 'Stim*Cue' => 'A', 'Proc*Item' => '2', 'Resp*Resp' => 'hello world', 'Resp*RT' => 12.231231, 'Resp*RT1' => 2.435452, 'Resp*RT2' => 11.254728, 'Resp*Focu' => 0.9812340000000001, 'Resp*Acc' => 100, 'Resp*Len' => 1, 'Resp*Str' => 1, 'Resp*JOL' => '100'), $files[0]); echo 't1 is using the benchmark function, t2 is without<br><br>'; $iterations = 100; $time = benchmark('arrayToLine', $iterations, $args); echo 't1: ' . $time . '<br>'; $start = microtime(true); for ($i = 0; $i < $iterations; ++$i) { arrayToLine($args[0], $files[1]); } $time = microtime(true) - $start; echo 't2: ' . $time;
$a = microtime(true); for ($i = 0; $i < $iterations; ++$i) { $r = Parser::parse($term); } $totalExecutionTime = microtime(true) - $a; print "parser : " . round($totalExecutionTime, 6) . "s " . round($totalExecutionTime / $iterations, 10) . "s per operation\n"; // time taken by scanner $a = microtime(true); for ($i = 0; $i < $iterations; ++$i) { $s = new Scanner($term); } $totalExecutionTime = microtime(true) - $a; print "scanner : " . round($totalExecutionTime, 6) . "s " . round($totalExecutionTime / $iterations, 10) . "s per operation\n"; // calculations using parser $c = new Context(); $p = new Parser(new Scanner($term)); // time taken to evaluate parser stack $a = microtime(true); for ($i = 0; $i < $iterations; ++$i) { $r = $p->reduce($c); } $totalExecutionTime = microtime(true) - $a; print "reduce : " . round($totalExecutionTime, 6) . "s " . round($totalExecutionTime / $iterations, 10) . "s per operation\n\n"; } benchmark('1+1'); benchmark('-2*4/2'); benchmark('3+4*2/(1-5)*2*3'); benchmark('3+4*2/(1-5)*2*3+3+4*2/(1-5)*2*3'); benchmark('3+4*2/(1-5)*2*3+3+4*2/(1-5)*2*3*3+4*2/(1-5)*2*3+3+4*2/(1-5)*2*3'); benchmark('3.2+4.1*2.5/(1.1-5.4)*2.7*3.9+3.1+4.4*2.4/(1.1-5.5)*2.4*3.9*3.7+4.8*' . '2.3/(1.7-5.9)*2.4*3.1+3.2+4.6*2.8/(1.5-5.6)*2.1*3.9*3.2+4.1*2.5/(1.1-5.4)*' . '2.7*3.9+3.1+4.4*2.4/(1.1-5.5)*2.4*3.9*3.7+4.8*2.3/(1.7-5.9)*2.4*3.1+3.2+4.' . '6*2.8/(1.5-5.6)*2.1*3.9+6*2.8/(1.5-5.6)*2.1*3.9-6*2.8/(1.5-5.6)*2.1*3.9+1+' . '2.3/(1.7-5.9)*2.4*3.1+3.2+4.6*2.8/(1.5-5.6)*2.1*3.9*3.2+4.1*2.5/(1.1-5.4)*' . '2.7*3.9+3.1+4.4*2.4/(1.1-5.5)*2.4*3.9*3.7+4.8*2.3/(1.7-5.9)*2.4*3.1+3.2+4.' . '6*2.8/(1.5-5.6)*2.1*3.9+6*2.8/(1.5-5.6)*2.1*3.9-6*2.8/(1.5-5.6)*2.1*3.9+1');
$output .= $username[$i]; } } $output = substr(strtolower(trim($output)), 0, 50); return $output; } $iterations = 1000; $username = '******'; echo "with username {$username}<br>"; echo benchmark('cleanUsernamePreg_Replace', $iterations, array($username)); echo ' ' . cleanUsernamePreg_Replace($username) . '<br>'; echo benchmark('cleanUsernameStrlen', $iterations, array($username)); echo ' ' . cleanUsernameStrlen($username) . '<br>'; $username = '******'; echo "with username {$username}<br>"; echo benchmark('cleanUsernamePreg_Replace', $iterations, array($username)); echo ' ' . cleanUsernamePreg_Replace($username) . '<br>'; echo benchmark('cleanUsernameStrlen', $iterations, array($username)); echo ' ' . cleanUsernameStrlen($username) . '<br>'; $username = '******'; echo "with username {$username}<br>"; echo benchmark('cleanUsernamePreg_Replace', $iterations, array($username)); echo ' ' . cleanUsernamePreg_Replace($username) . '<br>'; echo benchmark('cleanUsernameStrlen', $iterations, array($username)); echo ' ' . cleanUsernameStrlen($username) . '<br>'; $username = '******'; echo "with username {$username}<br>"; echo benchmark('cleanUsernamePreg_Replace', $iterations, array($username)); echo ' ' . cleanUsernamePreg_Replace($username) . '<br>'; echo benchmark('cleanUsernameStrlen', $iterations, array($username)); echo ' ' . cleanUsernameStrlen($username) . '<br>';
<?php ini_set('memory_limit', '1G'); const ARRAY_SIZE = 5000000; function benchmark($arr) { for ($i = 0; $i < ARRAY_SIZE; $i++) { $arr[$i] = $i; } $start = microtime(true); for ($i = 0; $i < ARRAY_SIZE; $i++) { $k = $arr[$i]; } return microtime(true) - $start; } $a1 = array(); print benchmark($a1) . "\n"; unset($a1); $a2 = new SplFixedArray(ARRAY_SIZE); print benchmark($a2) . "\n"; unset($a2); $a3 = new Judy(Judy::INT_TO_INT); print benchmark($a3) . "\n"; unset($a3);
echo benchmark(function () { //Get a new instance of $topics each time to avoid maphper caching $topics = getTopics(); $template = new \CDS\Builder(file_get_contents('template.xml'), 'topics.cds', $topics); $output = $template->output(); }); echo "\n\n"; echo 'Benchmarking tpl:'; echo benchmark(function () { //Get a new instance of $topics each time to avoid maphper caching $topics = getTopics(); $data = ['topics' => $topics]; extract($data); ob_start(); require 'template.php'; $output = ob_get_clean(); }); echo "\n\n"; echo 'Bechmkaring cached output:'; echo benchmark(function () { //Get a new instance of $topics each time to avoid maphper caching if (is_file('tmp/template.cache')) { $output = file_get_contents('tmp/template.cache'); } else { $topics = getTopics(); $template = new \CDS\Builder(file_get_contents('template.xml'), 'topics.cds', $topics); $output = $template->output(); file_put_contents('tmp/template.cache', $output); } }); echo "\n\n";
function static_benchmark() { $server = "http://localhost/service/static.html"; benchmark($server); }
<?php test_conn(); basic(); benchmark(300); mul_get(); mul_set(); mul_del(); mul_benchmark(300, 16); function test_conn() { $short_conn = array(); $long_conn = array(); for ($i = 0; $i < 20; ++$i) { list($err, $handle) = bht_open("test"); assert($err === false); assert($handle !== null); $short_conn[] = $handle; } for ($i = 0; $i < 40; ++$i) { list($err, $handle) = bht_popen("test"); assert($err === false); assert($handle !== null); $long_conn[] = $handle; } foreach ($short_conn as $handle) { $err = bht_close($handle); assert($err === false); } foreach ($long_conn as $handle) { $err = bht_close($handle);