<?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");
- Output for git.master
- empty_loop 0.015
func() 0.050 0.034
undef_func() 0.059 0.044
int_func() 0.026 0.011
$x = self::$x 0.067 0.052
self::$x = 0 0.058 0.043
isset(self::$x) 0.067 0.052
empty(self::$x) 0.069 0.054
$x = Foo::$x 0.040 0.024
Foo::$x = 0 0.031 0.016
isset(Foo::$x) 0.041 0.026
empty(Foo::$x) 0.046 0.031
self::f() 0.073 0.058
Foo::f() 0.068 0.052
$x = $this->x 0.034 0.019
$this->x = 0 0.031 0.016
$this->x += 2 0.055 0.039
++$this->x 0.048 0.033
--$this->x 0.048 0.033
$this->x++ 0.049 0.033
$this->x-- 0.049 0.033
isset($this->x) 0.050 0.035
empty($this->x) 0.061 0.045
$this->f() 0.062 0.047
$x = Foo::TEST 0.056 0.040
new Foo() 0.201 0.186
$x = TEST 0.028 0.013
$x = $_GET 0.056 0.041
$x = $GLOBALS['v'] 0.051 0.036
$x = $hash['v'] 0.064 0.048
$x = $str[0] 0.045 0.030
$x = $a ?: null 0.044 0.029
$x = $f ?: tmp 0.043 0.027
$x = $f ? $f : $a 0.048 0.033
$x = $f ? $f : tmp 0.049 0.034
------------------------
Total 1.882
- Output for git.master_jit
- empty_loop 0.015
func() 0.053 0.038
undef_func() 0.069 0.054
int_func() 0.026 0.010
$x = self::$x 0.066 0.050
self::$x = 0 0.058 0.043
isset(self::$x) 0.067 0.051
empty(self::$x) 0.069 0.053
$x = Foo::$x 0.039 0.024
Foo::$x = 0 0.029 0.014
isset(Foo::$x) 0.037 0.021
empty(Foo::$x) 0.039 0.024
self::f() 0.074 0.058
Foo::f() 0.063 0.048
$x = $this->x 0.034 0.019
$this->x = 0 0.031 0.016
$this->x += 2 0.056 0.041
++$this->x 0.048 0.033
--$this->x 0.048 0.033
$this->x++ 0.048 0.033
$this->x-- 0.048 0.033
isset($this->x) 0.050 0.035
empty($this->x) 0.056 0.041
$this->f() 0.062 0.046
$x = Foo::TEST 0.056 0.040
new Foo() 0.194 0.179
$x = TEST 0.029 0.014
$x = $_GET 0.072 0.057
$x = $GLOBALS['v'] 0.065 0.050
$x = $hash['v'] 0.063 0.048
$x = $str[0] 0.045 0.029
$x = $a ?: null 0.044 0.029
$x = $f ?: tmp 0.043 0.027
$x = $f ? $f : $a 0.048 0.033
$x = $f ? $f : tmp 0.049 0.034
------------------------
Total 1.895
- Output for rfc.property-hooks
- empty_loop 0.013
func() 0.034 0.021
undef_func() 0.042 0.029
int_func() 0.034 0.021
$x = self::$x 0.057 0.044
self::$x = 0 0.052 0.039
isset(self::$x) 0.060 0.046
empty(self::$x) 0.069 0.056
$x = Foo::$x 0.047 0.034
Foo::$x = 0 0.031 0.018
isset(Foo::$x) 0.045 0.032
empty(Foo::$x) 0.054 0.041
self::f() 0.084 0.071
Foo::f() 0.059 0.046
$x = $this->x 0.036 0.023
$this->x = 0 0.024 0.011
$this->x += 2 0.043 0.030
++$this->x 0.046 0.033
--$this->x 0.050 0.037
$this->x++ 0.046 0.032
$this->x-- 0.051 0.038
isset($this->x) 0.063 0.050
empty($this->x) 0.070 0.057
$this->f() 0.049 0.035
$x = Foo::TEST 0.054 0.041
new Foo() 0.143 0.130
$x = TEST 0.035 0.022
$x = $_GET 0.051 0.037
$x = $GLOBALS['v'] 0.050 0.037
$x = $hash['v'] 0.068 0.055
$x = $str[0] 0.049 0.036
$x = $a ?: null 0.045 0.032
$x = $f ?: tmp 0.050 0.037
$x = $f ? $f : $a 0.036 0.022
$x = $f ? $f : tmp 0.039 0.025
------------------------
Total 1.779
This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches
Archived branches
Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:
45.46 ms | 403 KiB | 8 Q