@ 2014-05-07T14:17:19Z <?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.7 0.003 2.000 18.56 8.3.6 0.010 1.992 16.75 8.3.5 0.008 1.995 17.51 8.3.4 0.010 1.994 19.20 8.3.3 0.007 1.998 19.25 8.3.2 0.003 1.453 18.98 8.3.1 0.007 1.438 20.78 8.3.0 0.003 1.446 19.63 8.2.18 0.013 1.989 16.63 8.2.17 0.010 1.994 22.96 8.2.16 0.010 1.992 21.30 8.2.15 0.003 1.540 24.18 8.2.14 0.007 1.530 24.66 8.2.13 0.007 1.499 26.16 8.2.12 0.017 1.632 17.88 8.2.11 0.010 1.992 22.08 8.2.10 0.010 1.905 18.16 8.2.9 0.000 1.875 18.28 8.2.8 0.003 1.845 17.97 8.2.7 0.010 1.865 18.00 8.2.6 0.007 1.988 18.41 8.2.5 0.003 1.857 18.07 8.2.4 0.003 1.863 18.47 8.2.3 0.015 1.984 18.38 8.2.2 0.007 1.893 18.00 8.2.1 0.010 1.888 18.17 8.2.0 0.013 1.988 17.61 8.1.28 0.020 1.981 25.92 8.1.27 0.007 1.611 24.66 8.1.26 0.003 1.523 26.35 8.1.25 0.007 1.464 28.09 8.1.24 0.007 1.995 23.86 8.1.23 0.007 1.826 21.10 8.1.22 0.010 1.867 18.16 8.1.21 0.003 1.829 19.21 8.1.20 0.003 1.989 17.72 8.1.19 0.003 1.869 18.00 8.1.18 0.007 1.859 18.10 8.1.17 0.000 1.882 19.01 8.1.16 0.010 1.856 19.26 8.1.15 0.003 1.873 19.00 8.1.14 0.010 1.897 17.72 8.1.13 0.003 1.877 18.13 8.1.12 0.003 1.909 17.79 8.1.11 0.010 1.857 17.72 8.1.10 0.007 1.848 17.87 8.1.9 0.007 1.999 17.93 8.1.8 0.003 1.885 17.84 8.1.7 0.003 1.891 17.71 8.1.6 0.007 1.996 17.96 8.1.5 0.007 1.996 17.85 8.1.4 0.007 1.994 17.91 8.1.3 0.000 2.004 17.95 8.1.2 0.000 2.003 17.94 8.1.1 0.007 1.996 17.82 8.1.0 0.003 1.999 17.86 8.0.30 0.007 1.926 20.17 8.0.29 0.010 1.943 16.86 8.0.28 0.003 2.000 18.75 8.0.27 0.007 1.936 17.44 8.0.26 0.007 1.956 17.23 8.0.25 0.007 1.947 17.31 8.0.24 0.010 1.947 17.33 8.0.23 0.007 1.959 17.28 8.0.22 0.010 1.950 17.23 8.0.21 0.003 1.956 17.29 8.0.20 0.003 1.998 17.39 8.0.19 0.007 1.997 17.16 8.0.18 0.003 1.999 17.25 8.0.17 0.003 2.000 17.25 8.0.16 0.003 2.000 17.18 8.0.15 0.007 1.997 17.19 8.0.14 0.010 1.981 17.13 8.0.13 0.000 2.002 13.77 8.0.12 0.003 1.998 17.09 8.0.11 0.007 1.996 17.04 8.0.10 0.023 1.983 17.09 8.0.9 0.003 1.999 17.09 8.0.8 0.010 1.992 17.09 8.0.7 0.003 1.999 16.99 8.0.6 0.003 1.998 17.24 8.0.5 0.007 1.995 17.04 8.0.3 0.010 1.991 17.39 8.0.2 0.015 1.984 17.27 8.0.1 0.000 2.002 17.18 8.0.0 0.018 1.965 17.15 7.4.33 0.000 2.000 13.37 7.4.32 0.003 1.998 16.69 7.4.30 0.000 2.002 16.81 7.4.29 0.000 2.004 16.78 7.4.28 0.000 2.001 16.70 7.4.27 0.007 1.994 16.64 7.4.26 0.000 2.003 13.63 7.4.25 0.000 2.001 16.62 7.4.24 0.003 2.000 16.71 7.4.23 0.003 1.998 16.52 7.4.22 0.023 1.978 16.72 7.4.21 0.017 1.981 16.70 7.4.20 0.003 1.999 16.58 7.4.19 0.003 1.999 16.84 7.4.16 0.020 1.973 16.94 7.4.15 0.026 1.976 16.80 7.4.14 0.018 1.979 16.90 7.4.13 0.010 1.988 16.81 7.4.12 0.016 1.993 16.74 7.4.11 0.013 2.445 16.63 7.4.10 0.007 2.470 16.82 7.4.9 0.016 2.423 16.82 7.4.8 0.032 2.260 19.39 7.4.7 0.026 2.415 16.86 7.4.6 0.023 2.452 16.79 7.4.5 0.003 2.266 16.70 7.4.4 0.000 2.497 16.65 7.4.3 0.010 2.452 16.68 7.3.33 0.000 2.004 13.64 7.3.32 0.003 1.998 13.69 7.3.31 0.007 1.996 16.62 7.3.30 0.000 2.002 16.70 7.3.29 0.007 1.990 16.57 7.3.28 0.015 1.981 16.62 7.3.27 0.003 2.001 16.55 7.3.26 0.016 1.977 16.61 7.3.25 0.016 1.984 16.78 7.3.24 0.013 2.002 16.91 7.3.23 0.013 2.459 16.66 7.3.21 0.010 2.438 16.57 7.3.20 0.026 2.427 16.72 7.3.19 0.019 2.431 16.82 7.3.18 0.020 2.390 16.57 7.3.17 0.041 2.174 16.59 7.3.16 0.016 2.411 16.80 7.2.33 0.016 2.456 16.98 7.2.32 0.013 2.445 16.98 7.2.31 0.016 2.409 17.08 7.2.30 0.013 2.446 17.02 7.2.29 0.016 2.455 17.11 7.2.10 0.028 1.369 14.68 7.1.22 0.053 1.827 14.21 5.6.38 0.013 1.622 14.42
preferences:dark mode live preview
64.19 ms | 401 KiB | 5 Q