<?php
//https://github.com/php/php-src/blob/master/Zend/micro_bench.php
function hallo() {}
function hallo2() {}
function simpleucall($n) { for ($i = 0; $i < $n; $i++) hallo(); }
function simpleudcall($n) { for ($i = 0; $i < $n; $i++) hallo2(); }
function simpleicall($n) { for ($i = 0; $i < $n; $i++) func_num_args(); }
define('TEST', null);
function read_const($n) { for ($i = 0; $i < $n; ++$i) $x = TEST; }
function read_auto_global($n) { for ($i = 0; $i < $n; ++$i) $x = $_GET; }
$g_var = 0;
function read_global_var($n) { for ($i = 0; $i < $n; ++$i) $x = $GLOBALS['g_var']; }
function read_hash($n) { $hash = array('test' => 0); for ($i = 0; $i < $n; ++$i) $x = $hash['test'];}
function read_str_offset($n) { $str = "test"; for ($i = 0; $i < $n; ++$i) $x = $str[1]; }
function issetor($n) { $val = array(0,1,2,3,4,5,6,7,8,9); for ($i = 0; $i < $n; ++$i) $x = $val ?: null; }
function issetor2($n) { $f = false; $j = 0; for ($i = 0; $i < $n; ++$i) $x = $f ?: $j + 1; }
function ternary($n) { $val = array(0,1,2,3,4,5,6,7,8,9); $f = false; for ($i = 0; $i < $n; ++$i) $x = $f ? null : $val; }
function ternary2($n) { $f = false; $j = 0; for ($i = 0; $i < $n; ++$i) $x = $f ? $f : $j + 1; }
/*****/
function getmicrotime() { $t = gettimeofday(); return ($t['sec'] + $t['usec'] / 1000000);}
const N = 50000;
simpleucall(N);
simpleudcall(N);
simpleicall(N);
read_const(N);
read_auto_global(N);
read_global_var(N);
read_hash(N);
read_str_offset(N);
issetor(N);
issetor2(N);
ternary(N);
ternary2(N);
preferences:
38.25 ms | 402 KiB | 5 Q