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 = 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");

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.0130.17816.63
8.3.50.0130.17816.71
8.3.40.0100.18518.91
8.3.30.0070.18519.09
8.3.20.0000.09019.02
8.3.10.0100.08320.73
8.3.00.0030.08719.50
8.2.180.0130.18116.63
8.2.170.0070.19022.96
8.2.160.0070.17919.33
8.2.150.0070.08225.66
8.2.140.0100.08124.66
8.2.130.0070.09126.16
8.2.120.0030.08920.71
8.2.110.0030.16321.06
8.2.100.0030.13417.89
8.2.90.0070.15119.58
8.2.80.0030.12921.19
8.2.70.0000.13417.75
8.2.60.0070.13818.17
8.2.50.0030.13018.07
8.2.40.0030.13618.47
8.2.30.0030.12718.18
8.2.20.0070.13719.66
8.2.10.0070.12318.00
8.2.00.0000.13018.04
8.1.280.0100.19525.92
8.1.270.0100.07923.99
8.1.260.0030.09026.35
8.1.250.0070.09528.09
8.1.240.0070.15322.71
8.1.230.0030.13221.05
8.1.220.0000.13118.04
8.1.210.0000.13219.09
8.1.200.0030.13017.38
8.1.190.0070.12517.77
8.1.180.0000.13318.10
8.1.170.0100.12418.96
8.1.160.0070.12419.08
8.1.150.0030.12818.80
8.1.140.0070.12517.71
8.1.130.0030.12817.95
8.1.120.0000.13117.74
8.1.110.0000.13217.69
8.1.100.0000.13217.65
8.1.90.0070.12517.61
8.1.80.0030.12917.63
8.1.70.0000.13117.73
8.1.60.0070.15917.67
8.1.50.0070.15917.66
8.1.40.0070.15917.69
8.1.30.0030.16917.74
8.1.20.0030.16317.73
8.1.10.0030.16317.77
8.1.00.0000.16617.73
8.0.300.0070.12520.11
8.0.290.0030.12817.00
8.0.280.0030.13118.56
8.0.270.0030.12817.52
8.0.260.0030.12617.00
8.0.250.0030.12717.18
8.0.240.0100.12217.20
8.0.230.0000.13017.15
8.0.220.0030.12917.20
8.0.210.0070.12317.10
8.0.200.0030.14417.09
8.0.190.0070.16017.10
8.0.180.0030.16217.23
8.0.170.0030.16517.10
8.0.160.0030.17117.13
8.0.150.0070.16117.01
8.0.140.0040.16917.16
8.0.130.0030.16013.63
8.0.120.0030.16417.13
8.0.110.0000.16817.19
8.0.100.0000.16517.05
8.0.90.0000.16617.20
8.0.80.0130.25617.07
8.0.70.0030.16317.14
8.0.60.0030.16517.20
8.0.50.0000.17017.17
8.0.30.0210.24717.24
8.0.20.0130.23517.37
8.0.10.0070.16317.20
8.0.00.0170.30816.96
7.4.330.0000.16013.13
7.4.320.0070.15216.71
7.4.300.0000.15716.79
7.4.290.0030.18916.71
7.4.280.0070.18716.80
7.4.270.0070.18616.72
7.4.260.0000.19613.41
7.4.250.0000.19516.77
7.4.240.0030.19016.80
7.4.230.0030.19416.54
7.4.220.0100.35016.71
7.4.210.0100.27716.89
7.4.200.0030.18916.54
7.4.190.0030.19116.84
7.4.160.0100.26616.64
7.4.150.0070.28716.89
7.4.140.0120.39016.88
7.4.130.0130.28016.83
7.4.120.0130.27416.81
7.4.110.0170.30416.66
7.4.100.0160.29816.68
7.4.90.0150.29616.65
7.4.80.0100.30519.39
7.4.70.0100.28316.67
7.4.60.0170.29316.85
7.4.50.0030.13716.67
7.4.40.0070.21216.63
7.4.30.0180.27416.64
7.3.330.0030.21013.45
7.3.320.0030.20213.39
7.3.310.0070.20316.63
7.3.300.0070.20916.61
7.3.290.0130.32616.61
7.3.280.0130.32116.57
7.3.270.0200.29316.67
7.3.260.0100.31616.74
7.3.250.0140.30816.50
7.3.240.0100.31117.06
7.3.230.0070.29116.77
7.3.210.0130.34916.61
7.3.200.0090.35416.83
7.3.190.0030.49116.61
7.3.180.0070.32616.86
7.3.170.0070.29016.91
7.3.160.0070.29616.71
7.2.330.0130.34116.99
7.2.320.0060.49716.88
7.2.310.0090.49317.13
7.2.300.0100.38417.04
7.2.290.0230.40716.98
7.2.100.1120.36115.06
7.2.90.0290.28314.89
7.2.80.0680.26214.93
7.2.70.0580.25815.27
7.2.60.0780.26615.36
7.2.50.0160.29615.51
7.2.40.0200.26615.30
7.2.30.0750.24115.52
7.2.20.0600.28115.14
7.2.10.0590.27615.16
7.2.00.0130.26714.87
7.1.220.0730.29614.26
7.1.210.0690.32014.25
7.1.200.0630.28913.82
7.1.190.0620.32114.11
7.1.180.0400.34514.09
7.1.170.0500.34213.90
7.1.160.0690.28214.18
7.1.150.1690.33713.93
7.1.140.0620.30214.07
7.1.130.0730.29714.13
7.1.120.0750.32614.26
7.1.110.0130.28414.33
7.1.100.0100.31314.21
7.1.90.0420.31813.86
7.1.80.0550.35014.09
7.1.70.0230.29514.28
7.1.60.0360.33832.20
7.1.50.0680.29332.11
7.1.40.1020.27632.26
7.1.30.0730.29732.10
7.1.20.0440.28732.06
7.1.10.1840.34114.18
7.1.00.0630.31113.94
7.0.310.0920.29513.85
7.0.300.0700.36013.63
7.0.290.0520.28113.79
7.0.280.0530.34513.96
7.0.270.0510.30413.91
7.0.260.0130.32113.70
7.0.250.0100.34413.64
7.0.240.0260.30213.84
7.0.230.0440.29613.96
7.0.220.0640.28513.53
7.0.210.0470.27713.75
7.0.200.0170.36013.64
7.0.190.0790.44813.81
7.0.180.0210.32013.89
7.0.170.0410.31613.71
7.0.160.0120.36213.75
7.0.150.1300.33113.64
7.0.140.1240.32113.81
7.0.130.0870.28313.60
7.0.120.0720.31013.61
7.0.110.0250.27313.91
7.0.100.1130.31113.67
7.0.90.0850.28213.70
7.0.80.0750.39713.42
7.0.70.0270.29913.36
7.0.60.0980.27413.49
7.0.50.0160.31914.07
7.0.40.1840.35413.72
7.0.30.0480.35613.57
7.0.20.1570.29013.72
7.0.10.1590.30813.92
7.0.00.0270.31613.67
5.6.380.0190.90214.82
5.6.370.0190.79414.60
5.6.360.0130.85014.77
5.6.350.0130.78114.54
5.6.340.0100.92714.54
5.6.330.0100.75314.49
5.6.320.0090.76914.76
5.6.310.0130.81114.41
5.6.300.0290.83614.46
5.6.290.0421.03914.71
5.6.280.0590.90014.74
5.6.270.0310.81614.64
5.6.260.0530.97914.27
5.6.250.0610.82914.35
5.6.240.0270.85814.36
5.6.230.0260.92814.51
5.6.220.0370.79714.51
5.6.210.0160.87314.14
5.6.200.0471.01613.98
5.6.190.0310.91314.57
5.6.180.0520.93114.14
5.6.170.0410.93414.54
5.6.160.0390.87714.41
5.6.150.0350.80514.70
5.6.140.0560.75714.56
5.6.130.0120.92714.46
5.6.120.0200.78114.63
5.6.110.0190.84214.55
5.6.100.0060.92714.36
5.6.90.0070.80114.53
5.6.80.0160.84314.16
5.6.70.0100.92914.32
5.6.60.0151.14614.32
5.6.50.0260.84714.68
5.6.40.0090.81114.41
5.6.30.0130.83114.49
5.6.20.0160.83014.20
5.6.10.0000.80414.27
5.6.00.0100.86214.05
5.5.380.0310.80112.68
5.5.370.0221.03212.68
5.5.360.0260.79712.68
5.5.350.0120.83712.68
5.5.340.0180.90012.68
5.5.330.0250.85312.68
5.5.320.0330.79112.68
5.5.310.0580.98212.68
5.5.300.0090.79012.68
5.5.290.0190.77512.68
5.5.280.0130.75612.68
5.5.270.0060.81512.68
5.5.260.0160.90512.68
5.5.250.0090.82512.68
5.5.240.0060.77912.68
5.5.230.0251.01312.68
5.5.220.0160.88012.68
5.5.210.0220.79612.68
5.5.200.0100.75012.68
5.5.190.0030.80612.68
5.5.180.0250.90712.68
5.5.170.0100.80314.31
5.5.160.0030.79212.68
5.5.150.0060.91712.68
5.5.140.0061.01812.68
5.5.130.0230.77412.68
5.5.120.0360.89712.68
5.5.110.0180.90112.68
5.5.100.0160.94312.68
5.5.90.0160.94812.68
5.5.80.0070.88512.68
5.5.70.0200.87812.68
5.5.60.0541.00112.68
5.5.50.0260.94812.68
5.5.40.0251.03112.68
5.5.30.0420.81612.68
5.5.20.0380.76212.68
5.5.10.0380.78012.68
5.5.00.0300.92612.68
5.4.450.0100.85112.68
5.4.440.0100.76812.68
5.4.430.0131.26012.68
5.4.420.0130.88912.68
5.4.410.0130.92712.68
5.4.400.0060.88612.68
5.4.390.0180.88412.68
5.4.380.0091.21012.68
5.4.370.0121.00012.68
5.4.360.0130.81412.68
5.4.350.0030.81012.68
5.4.340.0180.87312.68
5.4.330.0131.02212.68
5.4.320.0030.85212.68
5.4.310.0030.86612.68
5.4.300.0130.84912.68
5.4.290.0130.77812.68
5.4.280.0160.85212.68
5.4.270.0280.86712.68
5.4.260.0230.88112.68
5.4.250.0380.86012.68
5.4.240.0321.09712.68
5.4.230.0470.96012.68
5.4.220.0260.97112.68
5.4.210.0401.17212.68
5.4.200.0470.93112.68
5.4.190.0220.87012.68
5.4.180.0160.85412.68
5.4.170.0090.81812.68
5.4.160.0310.91512.68
5.4.150.0270.82212.68
5.4.140.0370.95512.68
5.3.290.0130.96712.68
5.3.280.0321.36212.68
5.3.270.0211.05312.68
5.3.260.0310.98212.68
5.3.250.0191.00712.68
5.3.240.0350.95312.68

preferences:
40.03 ms | 401 KiB | 5 Q