3v4l.org

run code in 300+ PHP versions simultaneously
<?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 = 500; $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");

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).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0100.01317.00
8.3.50.0160.00316.80
8.3.40.0000.01619.27
8.3.30.0080.00819.04
8.3.20.0040.00419.12
8.3.10.0030.00620.79
8.3.00.0060.00319.75
8.2.180.0170.00718.55
8.2.170.0000.01622.96
8.2.160.0140.00319.34
8.2.150.0030.00624.18
8.2.140.0000.00824.66
8.2.130.0130.00626.16
8.2.120.0040.00420.75
8.2.110.0080.01621.04
8.2.100.0080.00418.06
8.2.90.0000.00919.50
8.2.80.0100.00019.53
8.2.70.0060.00318.00
8.2.60.0080.00418.18
8.2.50.0060.00318.07
8.2.40.0050.00318.41
8.2.30.0030.00618.43
8.2.20.0060.00419.67
8.2.10.0000.00818.19
8.2.00.0000.00818.20
8.1.280.0150.00625.92
8.1.270.0080.00023.99
8.1.260.0160.00326.35
8.1.250.0070.01128.09
8.1.240.0000.01122.67
8.1.230.0090.00321.05
8.1.220.0000.00818.03
8.1.210.0030.00619.15
8.1.200.0040.00717.86
8.1.190.0050.00317.91
8.1.180.0040.00418.10
8.1.170.0060.00319.21
8.1.160.0030.00519.15
8.1.150.0030.00618.96
8.1.140.0040.00417.76
8.1.130.0040.00418.14
8.1.120.0030.00517.85
8.1.110.0060.00317.74
8.1.100.0040.00417.83
8.1.90.0080.00017.72
8.1.80.0040.00417.90
8.1.70.0000.00717.76
8.1.60.0040.00517.89
8.1.50.0000.00817.73
8.1.40.0000.00817.87
8.1.30.0090.00017.97
8.1.20.0040.00418.02
8.1.10.0030.00617.78
8.1.00.0080.00017.82
8.0.300.0030.00520.11
8.0.290.0040.00417.00
8.0.280.0070.00018.67
8.0.270.0040.00417.57
8.0.260.0000.00717.18
8.0.250.0040.00417.35
8.0.240.0090.00017.34
8.0.230.0030.00517.21
8.0.220.0000.00817.28
8.0.210.0080.00017.27
8.0.200.0000.00917.16
8.0.190.0040.00417.19
8.0.180.0000.00817.24
8.0.170.0030.00617.18
8.0.160.0050.00317.18
8.0.150.0000.00817.14
8.0.140.0030.00617.23
8.0.130.0030.00313.75
8.0.120.0000.00917.13
8.0.110.0040.00417.30
8.0.100.0000.00917.16
8.0.90.0060.00317.07
8.0.80.0100.00717.27
8.0.70.0000.00817.23
8.0.60.0060.00317.04
8.0.50.0000.00817.09
8.0.30.0080.01217.44
8.0.20.0100.01317.49
8.0.10.0030.00617.57
8.0.00.0110.01117.15
7.4.330.0050.00013.33
7.4.320.0000.00716.84
7.4.300.0050.00316.88
7.4.290.0030.00516.89
7.4.280.0030.00616.79
7.4.270.0060.00316.82
7.4.260.0060.00013.56
7.4.250.0030.00716.93
7.4.240.0000.00816.91
7.4.230.0060.00316.93
7.4.220.0180.02316.80
7.4.210.0050.01017.00
7.4.200.0000.00816.96
7.4.190.0000.00816.68
7.4.160.0150.00316.95
7.4.150.0060.01816.84
7.4.140.0150.01416.71
7.4.130.0090.00917.04
7.4.120.0090.01416.95
7.4.110.0110.00717.01
7.4.100.0040.01516.63
7.4.90.0150.00516.88
7.4.80.0070.01319.39
7.4.70.0030.01417.03
7.4.60.0120.00616.88
7.4.50.0000.00816.92
7.4.40.0120.00316.71
7.4.30.0030.01316.73
7.4.00.0040.01515.40
7.3.330.0000.00713.61
7.3.320.0000.00613.67
7.3.310.0040.00416.71
7.3.300.0000.00916.64
7.3.290.0050.00916.68
7.3.280.0090.00716.67
7.3.270.0150.01216.81
7.3.260.0040.01516.88
7.3.250.0120.01016.92
7.3.240.0150.00316.86
7.3.230.0100.01416.74
7.3.210.0120.00717.05
7.3.200.0070.01116.66
7.3.190.0120.00616.87
7.3.180.0040.01516.77
7.3.170.0060.01216.77
7.3.160.0090.00916.72
7.3.120.0030.01315.35
7.2.330.0150.00917.15
7.2.320.0030.01616.97
7.2.310.0190.00917.06
7.2.300.0150.00916.84
7.2.290.0050.01617.24
7.2.60.0030.01317.10
7.2.00.0030.01319.20
7.1.200.0040.00715.82
7.1.100.0110.00717.95
7.1.70.0040.00417.39
7.1.60.0130.01319.17
7.1.50.0130.01316.76
7.1.00.0070.05022.63
7.0.200.0880.00015.07
7.0.140.0000.07722.24
7.0.120.0070.06322.34
7.0.100.0270.05720.35
7.0.90.0130.07020.10
7.0.80.0170.06320.29
7.0.70.0070.09020.33
7.0.60.0270.07719.98
7.0.50.0100.03720.64
7.0.40.0070.03720.25
7.0.30.0100.08720.15
7.0.20.0000.05720.06
7.0.10.0070.09320.32
7.0.00.0030.09719.94
5.6.280.0070.07321.24
5.6.250.0070.04320.89
5.6.240.0030.07720.78
5.6.230.0070.08320.80
5.6.220.0070.07320.95
5.6.210.0000.06020.76
5.6.200.0030.04321.08
5.6.190.0070.08021.25
5.6.180.0130.07021.25
5.6.170.0130.06321.17
5.6.160.0070.05021.15
5.6.150.0100.08321.18
5.6.140.0100.08021.25
5.6.130.0070.06021.29
5.6.120.0070.05721.15
5.6.110.0070.08721.13
5.6.100.0130.08721.24
5.6.90.0100.07721.12
5.6.80.0070.08720.80
5.6.70.0100.07720.73
5.6.60.0070.07320.69
5.6.50.0130.06320.57
5.6.40.0100.06020.52
5.6.30.0030.05020.68
5.6.20.0070.08720.61
5.6.10.0230.04320.60
5.6.00.0000.07720.69
5.5.380.0070.04020.68
5.5.370.0070.05020.69
5.5.360.0070.08020.69
5.5.350.0070.08020.53
5.5.340.0100.08321.03
5.5.330.0030.09321.14
5.5.320.0070.07720.86
5.5.310.0030.05720.88
5.5.300.0130.03721.03
5.5.290.0130.06720.91
5.5.280.0070.05321.06
5.5.270.0070.08720.98
5.5.260.0070.07020.93
5.5.250.0070.07720.90
5.5.240.0030.07020.61
5.5.230.0100.08020.32
5.5.220.0100.04320.58
5.5.210.0170.07720.53
5.5.200.0070.07020.52
5.5.190.0100.07320.27
5.5.180.0000.10020.39
5.5.160.0000.04720.36
5.5.150.0130.07320.37
5.5.140.0100.08020.48
5.5.130.0170.04720.54
5.5.120.0030.05320.28
5.5.110.0100.04020.58
5.5.100.0170.07020.21
5.5.90.0170.04320.18
5.5.80.0130.07320.27
5.5.70.0030.07020.15
5.5.60.0030.06720.30
5.5.50.0070.08020.38
5.5.40.0100.07720.08
5.5.30.0130.05320.38
5.5.20.0130.08020.35
5.5.10.0070.06720.36
5.5.00.0030.08020.08
5.4.450.0000.09319.68
5.4.440.0170.08019.26
5.4.430.0130.06719.47
5.4.420.0070.08319.51
5.4.410.0100.04319.52
5.4.400.0170.07019.11
5.4.390.0130.07319.11
5.4.380.0070.05018.95
5.4.370.0030.08719.02
5.4.360.0000.07019.14
5.4.350.0130.07319.18
5.4.340.0170.08319.01
5.4.320.0070.04019.16
5.4.310.0100.07719.02
5.4.300.0070.07719.18
5.4.290.0130.07019.19
5.4.280.0070.04019.16
5.4.270.0100.06319.22
5.4.260.0100.08019.36
5.4.250.0100.07319.21
5.4.240.0230.07319.25
5.4.230.0100.07019.22
5.4.220.0070.05719.24
5.4.210.0170.03719.42
5.4.200.0070.08019.22
5.4.190.0200.05719.00
5.4.180.0030.07319.08
5.4.170.0070.05719.18
5.4.160.0070.07319.07
5.4.150.0100.06019.27
5.4.140.0030.06716.70
5.4.130.0130.07316.50
5.4.120.0100.07716.69
5.4.110.0070.07716.48
5.4.100.0070.07316.46
5.4.90.0200.07016.54
5.4.80.0100.07016.59
5.4.70.0070.04016.66
5.4.60.0070.06716.64
5.4.50.0100.03716.63
5.4.40.0030.07016.56
5.4.30.0030.05316.44
5.4.20.0030.04716.56
5.4.10.0030.05716.72
5.4.00.0070.06016.15
5.3.290.0070.06015.09
5.3.280.0130.04014.80
5.3.270.0030.04714.81
5.3.260.0130.07315.03
5.3.250.0170.07714.77
5.3.240.0070.07314.79
5.3.230.0100.08014.91
5.3.220.0030.04314.77
5.3.210.0070.04714.86
5.3.200.0000.04314.86
5.3.190.0130.07314.77
5.3.180.0000.05014.77
5.3.170.0130.05714.78
5.3.160.0030.05014.99
5.3.150.0030.04714.78
5.3.140.0030.08014.93
5.3.130.0130.07014.96
5.3.120.0030.05314.83
5.3.110.0030.08714.84
5.3.100.0130.07314.23
5.3.90.0070.07714.33
5.3.80.0030.08714.22
5.3.70.0100.07014.34
5.3.60.0070.04014.29
5.3.50.0100.08714.03
5.3.40.0070.07714.18
5.3.30.0100.07014.01
5.3.20.0030.04313.96
5.3.10.0130.06713.84
5.3.00.0070.07314.06

preferences:
47.7 ms | 401 KiB | 5 Q