$x->post_dec_prop(N); $t = end_test($t, '$this->x--', $overhead); $x->isset_prop(N); $t = end_test($t, 'isset($this->x)', $overhead); $x->empty_prop(N); $t = end_test($t, 'empty($this->x)', $overhead); $x->call(N); $t = end_test($t, '$this->f()', $overhead); $x->read_const(N); $t = end_test($t, '$x = Foo::TEST', $overhead); create_object(N); $t = end_test($t, 'new Foo()', $overhead); read_const(N); $t = end_test($t, '$x = TEST', $overhead); read_auto_global(N); $t = end_test($t, '$x = $_GET', $overhead); read_global_var(N); $t = end_test($t, '$x = $GLOBALS[\'v\']', $overhead); read_hash(N); $t = end_test($t, '$x = $hash[\'v\']', $overhead); read_str_offset(N); $t = end_test($t, '$x = $str[0]', $overhead); issetor(N); $t = end_test($t, '$x = $a ?: null', $overhead); issetor2(N); $t = end_test($t, '$x = $f ?: tmp', $overhead); ternary(N); $t = end_test($t, '$x = $f ? $f : $a', $overhead); ternary2(N); $t = end_test($t, '$x = $f ? $f : tmp', $overhead); total($t0, "Total");
end_test('Repeated send (small array)', 'http 11 w. keep-alive and compression', $response); $c->keepalive = false; begin_test('Repeated send (small array)', 'http 11 w. compression'); $response = array(); for ($i = 0; $i < 25; $i++) { $resp =& $c->send($msg, 10, 'http11'); $response[] = $resp->value(); } end_test('Repeated send (small array)', 'http 11 w. compression', $response); } begin_test('Repeated send (small array)', 'multicall w. compression'); $response =& $c->send($msgs); foreach ($response as $key => &$val) { $val = $val->value(); } end_test('Repeated send (small array)', 'multicall w. compression', $response); } } // end of 'if no xdebug profiling' function begin_test($test_name, $test_case) { global $test_results; if (!isset($test_results[$test_name])) { $test_results[$test_name] = array(); } $test_results[$test_name][$test_case] = array(); $test_results[$test_name][$test_case]['time'] = microtime(true); } function end_test($test_name, $test_case, $test_result) { global $test_results;
} function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end - $start; $num = number_format($end - $start, 3); $pad = str_repeat(" ", 24 - strlen($name) - strlen($num)); echo $name . $pad . $num . "\n"; ob_start(); return getmicrotime(); } function total() { global $total; $pad = str_repeat("-", 24); echo $pad . "\n"; $num = number_format($total, 3); $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num)); echo "Total" . $pad . $num . "\n"; } $t0 = $t = start_test(); ary2(50000, 47); $t = end_test($t, "ary2(50000)");
} function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end - $start; $num = number_format($end - $start, 3); $pad = str_repeat(" ", 24 - strlen($name) - strlen($num)); echo $name . $pad . $num . "\n"; ob_start(); return getmicrotime(); } function total() { global $total; $pad = str_repeat("-", 24); echo $pad . "\n"; $num = number_format($total, 3); $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num)); echo "Total" . $pad . $num . "\n"; } $t0 = $t = start_test(); ary3(2000); $t = end_test($t, "ary3(2000)");
} function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end - $start; $num = number_format($end - $start, 3); $pad = str_repeat(" ", 24 - strlen($name) - strlen($num)); echo $name . $pad . $num . "\n"; ob_start(); return getmicrotime(); } function total() { global $total; $pad = str_repeat("-", 24); echo $pad . "\n"; $num = number_format($total, 3); $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num)); echo "Total" . $pad . $num . "\n"; } $t0 = $t = start_test(); simplecall(); $t = end_test($t, "simplecall");
} function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end - $start; $num = number_format($end - $start, 3); $pad = str_repeat(" ", 24 - strlen($name) - strlen($num)); echo $name . $pad . $num . "\n"; ob_start(); return getmicrotime(); } function total() { global $total; $pad = str_repeat("-", 24); echo $pad . "\n"; $num = number_format($total, 3); $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num)); echo "Total" . $pad . $num . "\n"; } $t0 = $t = start_test(); mandel(); $t = end_test($t, "mandel");
} function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end - $start; $num = number_format($end - $start, 3); $pad = str_repeat(" ", 24 - strlen($name) - strlen($num)); echo $name . $pad . $num . "\n"; ob_start(); return getmicrotime(); } function total() { global $total; $pad = str_repeat("-", 24); echo $pad . "\n"; $num = number_format($total, 3); $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num)); echo "Total" . $pad . $num . "\n"; } $t0 = $t = start_test(); hash1(590000); $t = end_test($t, "hash1(50000)");
$x->assign_add_prop(N); $t = end_test($t, '$this->x += 2', $overhead); $x->pre_inc_prop(N); $t = end_test($t, '++$this->x', $overhead); $x->pre_dec_prop(N); $t = end_test($t, '--$this->x', $overhead); $x->post_inc_prop(N); $t = end_test($t, '$this->x++', $overhead); $x->post_dec_prop(N); $t = end_test($t, '$this->x--', $overhead); $x->isset_prop(N); $t = end_test($t, 'isset($this->x)', $overhead); $x->empty_prop(N); $t = end_test($t, 'empty($this->x)', $overhead); $x->call(N); $t = end_test($t, '$this->f()', $overhead); $x->read_const(N); $t = end_test($t, '$x = Foo::TEST', $overhead); create_object(N); $t = end_test($t, 'new Foo()', $overhead); read_const(N); $t = end_test($t, '$x = TEST', $overhead); read_auto_global(N); $t = end_test($t, '$x = $_GET', $overhead); read_global_var(N); $t = end_test($t, '$x = $GLOBALS[\'v\']', $overhead); read_hash(N); $t = end_test($t, '$x = $hash[\'v\']', $overhead); read_str_offset(N); $t = end_test($t, '$x = $str[0]', $overhead); total($t0, "Total");
function main() { $tests = array("simple", "simplecall", "simpleucall", "simpleudcall", "mandel", "ackermann", "ary", "ary2", "ary3", "fibo", "hash2", "heapsort", "nestedloop", "sieve", "strcat", "binary_trees", "fannkuch", "fasta", "mandelbrot", "meteor_contest", "n_body", "spectral_norm"); $t0 = $t = start_test(); foreach ($tests as $test) { // if (!isset($argv[1]) || $argv[1] === $test) { $test(); $t = end_test($t, $test); //} } //if (!getenv('VERIFY')) { total(); //} }
} function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end - $start; $num = number_format($end - $start, 3); $pad = str_repeat(" ", 24 - strlen($name) - strlen($num)); echo $name . $pad . $num . "\n"; ob_start(); return getmicrotime(); } function total() { global $total; $pad = str_repeat("-", 24); echo $pad . "\n"; $num = number_format($total, 3); $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num)); echo "Total" . $pad . $num . "\n"; } $t0 = $t = start_test(); fibo(); $t = end_test($t, "fibo(30)");
} function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end - $start; $num = number_format($end - $start, 3); $pad = str_repeat(" ", 24 - strlen($name) - strlen($num)); echo $name . $pad . $num . "\n"; ob_start(); return getmicrotime(); } function total() { global $total; $pad = str_repeat("-", 24); echo $pad . "\n"; $num = number_format($total, 3); $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num)); echo "Total" . $pad . $num . "\n"; } $t0 = $t = start_test(); nestedloop(14); $t = end_test($t, "nestedloop(12)");
} function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end - $start; $num = number_format($end - $start, 3); $pad = str_repeat(" ", 24 - strlen($name) - strlen($num)); echo $name . $pad . $num . "\n"; ob_start(); return getmicrotime(); } function total() { global $total; $pad = str_repeat("-", 24); echo $pad . "\n"; $num = number_format($total, 3); $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num)); echo "Total" . $pad . $num . "\n"; } $t0 = $t = start_test(); hash2(1900); $t = end_test($t, "hash2(500)");
} function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end - $start; $num = number_format($end - $start, 3); $pad = str_repeat(" ", 24 - strlen($name) - strlen($num)); echo $name . $pad . $num . "\n"; ob_start(); return getmicrotime(); } function total() { global $total; $pad = str_repeat("-", 24); echo $pad . "\n"; $num = number_format($total, 3); $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num)); echo "Total" . $pad . $num . "\n"; } $t0 = $t = start_test(); heapsort(76000); $t = end_test($t, "heapsort(20000)");
} function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end - $start; $num = number_format($end - $start, 3); $pad = str_repeat(" ", 24 - strlen($name) - strlen($num)); echo $name . $pad . $num . "\n"; ob_start(); return getmicrotime(); } function total() { global $total; $pad = str_repeat("-", 24); echo $pad . "\n"; $num = number_format($total, 3); $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num)); echo "Total" . $pad . $num . "\n"; } $t0 = $t = start_test(); matrix(99); $t = end_test($t, "matrix(20)");
simpleudcall(); $t = end_test($t, "simpleudcall"); mandel(); $t = end_test($t, "mandel"); mandel2(); $t = end_test($t, "mandel2"); ackermann(7); $t = end_test($t, "ackermann(7)"); ary(50000); $t = end_test($t, "ary(50000)"); ary2(50000); $t = end_test($t, "ary2(50000)"); ary3(2000); $t = end_test($t, "ary3(2000)"); fibo(30); $t = end_test($t, "fibo(30)"); hash1(50000); $t = end_test($t, "hash1(50000)"); hash2(500); $t = end_test($t, "hash2(500)"); heapsort(20000); $t = end_test($t, "heapsort(20000)"); matrix(20); $t = end_test($t, "matrix(20)"); nestedloop(12); $t = end_test($t, "nestedloop(12)"); sieve(30); $t = end_test($t, "sieve(30)"); strcat(200000); $t = end_test($t, "strcat(200000)"); total($t0, "Total");
echo "Total" . $pad . $num . "\n"; } const N = 5000000; echo "Benchmark Zephir " . \Zephir\Compiler::VERSION . " \n"; $t = start_test(); $x = new \Test\Bench\Foo(); $x->empty_for_in_range(N); $t = end_test($t, 'empty for in range'); $x->read_prop(N); $t = end_test($t, '$x = $this->x'); $x->write_prop(N); $t = end_test($t, '$this->x = 0'); $x->assign_add_prop(N); $t = end_test($t, '$this->x += 2'); //$x->pre_inc_prop(N); //$t = end_test($t, '++$this->x'); //$x->pre_dec_prop(N); //$t = end_test($t, '--$this->x'); $x->post_inc_prop(N); $t = end_test($t, '$this->x++'); $x->post_dec_prop(N); $t = end_test($t, '$this->x--'); $x->isset_prop(N); $t = end_test($t, 'isset($this->x)'); $x->empty_prop(N); $t = end_test($t, 'empty($this->x)'); $x->call(N); $t = end_test($t, '$this->f()'); $x->read_const(N); $t = end_test($t, '$x = Foo::TEST'); total();
} function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end - $start; $num = number_format($end - $start, 3); $pad = str_repeat(" ", 24 - strlen($name) - strlen($num)); echo $name . $pad . $num . "\n"; ob_start(); return getmicrotime(); } function total() { global $total; $pad = str_repeat("-", 24); echo $pad . "\n"; $num = number_format($total, 3); $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num)); echo "Total" . $pad . $num . "\n"; } $t0 = $t = start_test(); simple(); $t = end_test($t, "simple");
$t = end_test($t, 'self::f()', $overhead); call_static(N); $t = end_test($t, 'Foo::f()', $overhead); $x = new Foo(); $x->read_prop(N); $t = end_test($t, '$x = $this->x', $overhead); $x->write_prop(N); $t = end_test($t, '$this->x = 0', $overhead); $x->assign_add_prop(N); $t = end_test($t, '$this->x += 2', $overhead); $x->pre_inc_prop(N); $t = end_test($t, '++$this->x', $overhead); $x->pre_dec_prop(N); $t = end_test($t, '--$this->x', $overhead); $x->post_inc_prop(N); $t = end_test($t, '$this->x++', $overhead); $x->post_dec_prop(N); $t = end_test($t, '$this->x--', $overhead); $x->isset_prop(N); $t = end_test($t, 'isset($this->x)', $overhead); $x->empty_prop(N); $t = end_test($t, 'empty($this->x)', $overhead); $x->call(N); $t = end_test($t, '$this->f()', $overhead); $x->read_const(N); $t = end_test($t, '$x = Foo::TEST', $overhead); create_object(N); $t = end_test($t, 'new Foo()', $overhead); read_const(N); $t = end_test($t, '$x = TEST', $overhead); total($t0, "Total");
} end_test('Repeated send (small array)', 'http 11', $response); } /*begin_test('Repeated send (small array)', 'multicall'); $response =& $c->send($msgs); end_test('Repeated send (small array)', 'multicall', $response);*/ if (function_exists('gzinflate')) { $c->accepted_compression = array('gzip'); $c->request_compression = 'gzip'; begin_test('Repeated send (small array)', 'http 10 w. compression'); $response = array(); for ($i = 0; $i < 25; $i++) { $resp =& $c->send($msg); $response[] = $resp->value(); } end_test('Repeated send (small array)', 'http 10 w. compression', $response); } } function begin_test($test_name, $test_case) { global $test_results; if (!isset($test_results[$test_name])) { $test_results[$test_name] = array(); } $test_results[$test_name][$test_case] = array(); list($micro, $sec) = explode(' ', microtime()); $test_results[$test_name][$test_case]['time'] = $sec + $micro; } function end_test($test_name, $test_case, $test_result) { global $test_results;
} function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end - $start; $num = number_format($end - $start, 3); $pad = str_repeat(" ", 24 - strlen($name) - strlen($num)); echo $name . $pad . $num . "\n"; ob_start(); return getmicrotime(); } function total() { global $total; $pad = str_repeat("-", 24); echo $pad . "\n"; $num = number_format($total, 3); $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num)); echo "Total" . $pad . $num . "\n"; } $t0 = $t = start_test(); ackermann(); $t = end_test($t, "ackermann()");
$response[] = $resp->value(); } end_test($testName, 'http 11 w. keep-alive and compression', $response); $c->keepalive = false; begin_test($testName, 'http 11 w. compression'); $response = array(); for ($i = 0; $i < 25; $i++) { $resp = $c->send($req, 10, 'http11'); $response[] = $resp->value(); } end_test($testName, 'http 11 w. compression', $response); } begin_test($testName, 'multicall w. compression'); $response = $c->send($reqs); foreach ($response as $key => &$val) { $val = $val->value(); } end_test($testName, 'multicall w. compression', $response); } } // end of 'if no xdebug profiling' echo "\n"; foreach ($test_results as $test => $results) { echo "\nTEST: {$test}\n"; foreach ($results as $case => $data) { echo " {$case}: {$data['time']} secs - Output data CRC: " . crc32(serialize($data['result'])) . "\n"; } } if ($is_web) { echo "\n</pre>\n</body>\n</html>\n"; }
} function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end - $start; $num = number_format($end - $start, 3); $pad = str_repeat(" ", 24 - strlen($name) - strlen($num)); echo $name . $pad . $num . "\n"; ob_start(); return getmicrotime(); } function total() { global $total; $pad = str_repeat("-", 24); echo $pad . "\n"; $num = number_format($total, 3); $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num)); echo "Total" . $pad . $num . "\n"; } $t0 = $t = start_test(); sieve(142); $t = end_test($t, "sieve(30)");