@ 2014-05-07T14:18:05Z <?php
//https://github.com/php/php-src/blob/master/Zend/micro_bench.php
function hallo() {
}
function simpleucall($n) {
for ($i = 0; $i < $n; $i++)
hallo();
}
function simpleudcall($n) {
for ($i = 0; $i < $n; $i++)
hallo2();
}
function hallo2() {
}
function simpleicall($n) {
for ($i = 0; $i < $n; $i++)
func_num_args();
}
class Foo {
static $a = 0;
public $b = 0;
const TEST = 0;
static function read_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = self::$a;
}
}
static function write_static($n) {
for ($i = 0; $i < $n; ++$i) {
self::$a = 0;
}
}
static function isset_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = isset(self::$a);
}
}
static function empty_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = empty(self::$a);
}
}
static function f() {
}
static function call_static($n) {
for ($i = 0; $i < $n; ++$i) {
self::f();
}
}
function read_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$x = $this->b;
}
}
function write_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$this->b = 0;
}
}
function assign_add_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$this->b += 2;
}
}
function pre_inc_prop($n) {
for ($i = 0; $i < $n; ++$i) {
++$this->b;
}
}
function pre_dec_prop($n) {
for ($i = 0; $i < $n; ++$i) {
--$this->b;
}
}
function post_inc_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$this->b++;
}
}
function post_dec_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$this->b--;
}
}
function isset_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$x = isset($this->b);
}
}
function empty_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$x = empty($this->b);
}
}
function g() {
}
function call($n) {
for ($i = 0; $i < $n; ++$i) {
$this->g();
}
}
function read_const($n) {
for ($i = 0; $i < $n; ++$i) {
$x = $this::TEST;
}
}
}
function read_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = Foo::$a;
}
}
function write_static($n) {
for ($i = 0; $i < $n; ++$i) {
Foo::$a = 0;
}
}
function isset_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = isset(Foo::$a);
}
}
function empty_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = empty(Foo::$a);
}
}
function call_static($n) {
for ($i = 0; $i < $n; ++$i) {
Foo::f();
}
}
function create_object($n) {
for ($i = 0; $i < $n; ++$i) {
$x = new Foo();
}
}
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 empty_loop($n) {
for ($i = 0; $i < $n; ++$i) {
}
}
function getmicrotime()
{
$t = gettimeofday();
return ($t['sec'] + $t['usec'] / 1000000);
}
function start_test()
{
ob_start();
return getmicrotime();
}
function end_test($start, $name, $overhead = null)
{
global $total;
global $last_time;
$end = getmicrotime();
ob_end_clean();
$last_time = $end-$start;
$total += $last_time;
$num = number_format($last_time,3);
$pad = str_repeat(" ", 24-strlen($name)-strlen($num));
if (is_null($overhead)) {
echo $name.$pad.$num."\n";
} else {
$num2 = number_format($last_time - $overhead,3);
echo $name.$pad.$num." ".$num2."\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";
}
const N = 5000000;
$t0 = $t = start_test();
empty_loop(N);
$t = end_test($t, 'empty_loop');
$overhead = $last_time;
simpleucall(N);
$t = end_test($t, 'func()', $overhead);
simpleudcall(N);
$t = end_test($t, 'undef_func()', $overhead);
simpleicall(N);
$t = end_test($t, 'int_func()', $overhead);
Foo::read_static(N);
$t = end_test($t, '$x = self::$x', $overhead);
Foo::write_static(N);
$t = end_test($t, 'self::$x = 0', $overhead);
Foo::isset_static(N);
$t = end_test($t, 'isset(self::$x)', $overhead);
Foo::empty_static(N);
$t = end_test($t, 'empty(self::$x)', $overhead);
read_static(N);
$t = end_test($t, '$x = Foo::$x', $overhead);
write_static(N);
$t = end_test($t, 'Foo::$x = 0', $overhead);
isset_static(N);
$t = end_test($t, 'isset(Foo::$x)', $overhead);
empty_static(N);
$t = end_test($t, 'empty(Foo::$x)', $overhead);
Foo::call_static(N);
$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);
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");
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.3.6 0.010 1.127 16.88 8.3.5 0.018 1.068 17.48 8.3.4 0.010 1.113 19.26 8.3.3 0.010 1.169 19.09 8.3.2 0.000 0.597 19.15 8.3.1 0.003 0.571 20.82 8.3.0 0.010 0.585 19.63 8.2.18 0.010 1.075 16.75 8.2.17 0.013 1.088 22.96 8.2.16 0.013 1.117 21.17 8.2.15 0.007 0.616 24.18 8.2.14 0.003 0.634 24.66 8.2.13 0.007 0.588 26.16 8.2.12 0.000 0.620 19.61 8.2.11 0.010 0.997 21.03 8.2.10 0.007 0.757 18.22 8.2.9 0.000 0.725 19.41 8.2.8 0.010 0.730 17.97 8.2.7 0.013 0.800 17.75 8.2.6 0.013 0.775 18.28 8.2.5 0.000 0.737 18.07 8.2.4 0.000 0.743 18.30 8.2.3 0.007 0.855 18.47 8.2.2 0.003 0.738 17.97 8.2.1 0.003 0.757 17.99 8.2.0 0.007 0.748 17.90 8.1.28 0.013 1.100 25.92 8.1.27 0.003 0.592 24.66 8.1.26 0.003 0.582 26.35 8.1.25 0.003 0.595 28.09 8.1.24 0.003 0.991 21.54 8.1.23 0.003 0.741 17.64 8.1.22 0.000 0.751 17.91 8.1.21 0.003 0.741 18.77 8.1.20 0.010 0.751 17.72 8.1.19 0.010 0.721 17.60 8.1.18 0.003 0.726 18.10 8.1.17 0.003 0.726 19.02 8.1.16 0.003 0.742 19.15 8.1.15 0.003 0.723 19.02 8.1.14 0.003 0.743 17.77 8.1.13 0.000 0.743 18.08 8.1.12 0.003 0.754 17.73 8.1.11 0.000 0.734 17.80 8.1.10 0.013 0.731 17.75 8.1.9 0.003 0.741 17.82 8.1.8 0.000 0.771 17.69 8.1.7 0.000 0.760 17.74 8.1.6 0.007 1.048 17.86 8.1.5 0.003 1.032 17.77 8.1.4 0.000 1.034 17.82 8.1.3 0.003 1.039 17.93 8.1.2 0.000 1.051 17.93 8.1.1 0.000 1.048 17.82 8.1.0 0.003 1.036 17.92 8.0.30 0.003 0.745 18.77 8.0.29 0.003 0.767 17.00 8.0.28 0.000 0.754 18.70 8.0.27 0.003 0.746 17.11 8.0.26 0.003 0.769 17.15 8.0.25 0.000 0.766 17.29 8.0.24 0.003 0.761 17.25 8.0.23 0.000 0.822 17.30 8.0.22 0.007 0.784 17.24 8.0.21 0.007 0.793 17.27 8.0.20 0.003 0.792 17.26 8.0.19 0.007 1.045 17.30 8.0.18 0.000 1.056 17.28 8.0.17 0.003 1.058 17.29 8.0.16 0.000 1.047 17.27 8.0.15 0.007 1.049 17.07 8.0.14 0.013 1.093 17.19 8.0.13 0.003 1.052 13.61 8.0.12 0.000 1.061 17.15 8.0.11 0.003 1.054 17.17 8.0.10 0.000 1.061 17.17 8.0.9 0.003 1.054 17.03 8.0.8 0.013 1.406 17.27 8.0.7 0.007 1.037 17.24 8.0.6 0.013 1.068 17.24 8.0.5 0.000 1.084 17.11 8.0.3 0.019 1.332 17.52 8.0.2 0.010 1.542 17.51 8.0.1 0.010 1.067 17.40 8.0.0 0.030 1.599 17.03 7.4.33 0.006 0.852 13.24 7.4.32 0.000 0.847 16.72 7.4.30 0.000 0.848 16.75 7.4.29 0.007 1.159 16.70 7.4.28 0.010 1.202 16.82 7.4.27 0.003 1.160 16.88 7.4.26 0.003 1.171 13.46 7.4.25 0.010 1.203 16.65 7.4.24 0.010 1.161 16.75 7.4.23 0.007 1.171 16.65 7.4.22 0.023 1.803 16.68 7.4.21 0.015 1.502 16.84 7.4.20 0.000 1.168 16.93 7.4.19 0.003 1.160 16.72 7.4.16 0.010 1.382 16.95 7.4.15 0.019 1.490 16.72 7.4.14 0.018 1.606 16.88 7.4.13 0.010 1.496 16.84 7.4.12 0.016 1.435 16.84 7.4.11 0.006 1.543 16.73 7.4.10 0.006 1.473 16.61 7.4.9 0.013 1.685 16.62 7.4.8 0.016 1.636 17.00 7.4.7 0.025 1.800 16.65 7.4.6 0.038 0.649 16.71 7.4.5 0.007 0.904 16.39 7.4.4 0.007 1.288 16.48 7.4.3 0.007 1.482 16.91 7.3.33 0.003 1.278 13.45 7.3.32 0.013 1.425 13.54 7.3.31 0.003 1.240 16.61 7.3.30 0.010 1.261 16.55 7.3.29 0.016 1.761 16.64 7.3.28 0.017 1.885 16.61 7.3.27 0.023 1.519 16.66 7.3.26 0.016 1.621 16.50 7.3.25 0.029 1.827 16.76 7.3.24 0.007 1.691 16.72 7.3.23 0.010 1.595 16.63 7.3.21 0.016 1.633 16.80 7.3.20 0.013 1.893 19.39 7.3.19 0.013 2.080 16.88 7.3.18 0.016 1.538 16.77 7.3.17 0.006 1.621 16.77 7.3.16 0.013 2.437 16.84 7.2.33 0.016 1.868 17.13 7.2.32 0.003 1.813 17.16 7.2.31 0.016 2.320 17.03 7.2.30 0.020 2.161 17.15 7.2.29 0.013 1.821 17.09 7.2.10 0.136 1.427 14.87 7.2.9 0.109 1.379 15.14 7.2.8 0.079 1.496 15.30 7.2.7 0.105 1.362 15.16 7.2.6 0.039 1.384 14.89 7.2.5 0.047 1.075 15.22 7.1.22 0.160 1.612 13.95 7.1.21 0.125 1.538 14.27 7.1.20 0.041 1.611 14.35 7.1.19 0.019 1.558 13.93 7.1.18 0.070 1.196 14.00 7.1.17 0.025 1.048 14.13 7.0.31 0.016 1.607 13.62 7.0.30 0.028 0.995 13.71 5.6.38 0.037 2.157 14.13 5.6.37 0.025 1.786 14.52 5.6.36 0.028 0.904 14.34
preferences:dark mode live preview
52.94 ms | 401 KiB | 5 Q