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 hallo2() {} function simpleucall($n) { for ($i = 0; $i < $n; $i++) hallo(); } function simpleudcall($n) { for ($i = 0; $i < $n; $i++) 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 = 50000; $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.03418.68
8.3.50.0070.04322.17
8.3.40.0070.03619.06
8.3.30.0070.03619.42
8.3.20.0070.01720.34
8.3.10.0030.02422.15
8.3.00.0030.01922.52
8.2.180.0130.04516.88
8.2.170.0100.03619.38
8.2.160.0000.04222.96
8.2.150.0030.02124.18
8.2.140.0070.01724.66
8.2.130.0040.01926.16
8.2.120.0000.02417.85
8.2.110.0090.02822.25
8.2.100.0100.02318.09
8.2.90.0030.02418.25
8.2.80.0000.02819.02
8.2.70.0060.02218.13
8.2.60.0060.02217.88
8.2.50.0000.02817.75
8.2.40.0070.02019.60
8.2.30.0030.02418.17
8.2.20.0070.02018.12
8.2.10.0030.02519.75
8.2.00.0030.02317.99
8.1.280.0070.05825.92
8.1.270.0070.01722.35
8.1.260.0070.01626.35
8.1.250.0070.01728.09
8.1.240.0100.02723.80
8.1.230.0030.02719.35
8.1.220.0030.02518.04
8.1.210.0060.02118.77
8.1.200.0100.02217.85
8.1.190.0000.02717.73
8.1.180.0060.02318.10
8.1.170.0030.02319.27
8.1.160.0030.02419.06
8.1.150.0000.02719.01
8.1.140.0070.02317.78
8.1.130.0120.01518.04
8.1.120.0070.02017.69
8.1.110.0090.01817.80
8.1.100.0060.02117.80
8.1.90.0000.02617.69
8.1.80.0070.02017.80
8.1.70.0030.02417.80
8.1.60.0060.03117.91
8.1.50.0000.03617.79
8.1.40.0000.03617.84
8.1.30.0000.03717.96
8.1.20.0070.03017.93
8.1.10.0090.02817.81
8.1.00.0030.03317.89
8.0.300.0070.02121.63
8.0.290.0060.02217.25
8.0.280.0060.02218.30
8.0.270.0060.02318.30
8.0.260.0030.02517.13
8.0.250.0040.02317.36
8.0.240.0000.02717.31
8.0.230.0030.02517.33
8.0.220.0030.02517.16
8.0.210.0030.02417.20
8.0.200.0000.02817.21
8.0.190.0090.02817.35
8.0.180.0060.03117.31
8.0.170.0040.03517.27
8.0.160.0100.02617.23
8.0.150.0000.03617.25
8.0.140.0030.03417.19
8.0.130.0000.03413.77
8.0.120.0030.03417.23
8.0.110.0030.03317.14
8.0.100.0100.02617.13
8.0.90.0000.03617.13
8.0.80.0070.04417.22
8.0.70.0000.03617.32
8.0.60.0070.03017.22
8.0.50.0030.03417.06
8.0.30.0100.06217.61
8.0.20.0200.04817.70
8.0.10.0030.03617.48
8.0.00.0070.05217.13
7.4.330.0030.02515.29
7.4.320.0040.02516.90
7.4.300.0000.02916.77
7.4.290.0040.03516.80
7.4.280.0070.03316.90
7.4.270.0030.03416.73
7.4.260.0030.03516.88
7.4.250.0060.03616.85
7.4.240.0030.03516.87
7.4.230.0000.03717.00
7.4.220.0150.04717.00
7.4.210.0090.05216.89
7.4.200.0000.03717.00
7.4.190.0000.03717.07
7.4.160.0140.03716.68
7.4.150.0190.03517.40
7.4.140.0100.04517.86
7.4.130.0090.05316.74
7.4.120.0110.05316.74
7.4.110.0100.04516.71
7.4.100.0090.05316.93
7.4.90.0070.04616.78
7.4.80.0120.04519.39
7.4.70.0130.06216.93
7.4.60.0060.04816.79
7.4.50.0040.04616.79
7.4.40.0130.03322.77
7.4.30.0060.04516.93
7.4.00.0070.04515.33
7.3.330.0060.03713.50
7.3.320.0000.03713.52
7.3.310.0000.03916.73
7.3.300.0000.03816.69
7.3.290.0100.04516.66
7.3.280.0120.06316.65
7.3.270.0100.05017.40
7.3.260.0120.06816.70
7.3.250.0100.04916.71
7.3.240.0040.05616.76
7.3.230.0190.03916.73
7.3.210.0100.04716.74
7.3.200.0130.07319.39
7.3.190.0030.08517.05
7.3.180.0060.04916.66
7.3.170.0100.04616.73
7.3.160.0090.07516.84
7.3.120.0080.05015.24
7.3.110.0070.06015.38
7.3.100.0030.04715.25
7.3.90.0070.04114.88
7.3.80.0070.04015.41
7.3.70.0100.04215.07
7.3.60.0030.03914.86
7.3.50.0070.03815.10
7.3.40.0030.04415.11
7.3.30.0130.03514.96
7.3.20.0060.04216.84
7.3.10.0030.04016.61
7.3.00.0070.03916.82
7.2.330.0030.07216.94
7.2.320.0130.05417.23
7.2.310.0060.08216.88
7.2.300.0120.05117.13
7.2.290.0120.04917.02
7.2.250.0100.06015.19
7.2.240.0130.04415.21
7.2.230.0030.04715.32
7.2.220.0100.03815.27
7.2.210.0100.04415.26
7.2.200.0030.04415.48
7.2.190.0100.04015.29
7.2.180.0070.04415.46
7.2.170.0100.04015.33
7.2.60.0030.04516.79
7.2.00.0040.03519.66
7.1.330.0070.09915.92
7.1.320.0030.09216.04
7.1.310.0000.10616.02
7.1.300.0070.09315.65
7.1.290.0100.09316.09
7.1.280.0130.08415.65
7.1.270.0030.09616.08
7.1.260.0070.08916.05
7.1.200.0100.03515.63
7.1.100.0000.06418.17
7.1.70.0030.05517.44
7.1.60.0070.07919.82
7.1.50.0030.06816.97
7.1.00.0000.13322.33
7.0.200.0070.05116.99
7.0.140.0070.12022.13
7.0.100.0070.11720.21
7.0.90.0000.12020.13
7.0.80.0270.11020.13
7.0.70.0000.12020.09
7.0.60.0170.12320.27
7.0.50.0200.11320.45
7.0.40.0070.11720.12
7.0.30.0070.09320.14
7.0.20.0070.07720.14
7.0.10.0070.12020.07
7.0.00.0000.06320.10
5.6.280.0030.18020.90
5.6.250.0030.13320.74
5.6.240.0130.18020.87
5.6.230.0100.16020.79
5.6.220.0030.13320.79
5.6.210.0130.12020.76
5.6.200.0070.14721.07
5.6.190.0030.13321.20
5.6.180.0130.15721.20
5.6.170.0030.10721.29
5.6.160.0100.14321.14
5.6.150.0030.13721.07
5.6.140.0070.10021.05
5.6.130.0130.09321.17
5.6.120.0030.11321.24
5.6.110.0100.15021.18
5.6.100.0070.11721.22
5.6.90.0070.17721.13
5.6.80.0030.18720.54
5.6.70.0100.18020.60
5.6.60.0070.16720.54
5.6.50.0270.11720.54
5.6.40.0230.15320.55
5.6.30.0130.12020.49
5.6.20.0070.16320.50
5.6.10.0100.13320.46
5.6.00.0000.13020.53
5.5.380.0100.15320.46
5.5.370.0100.16720.48
5.5.360.0170.09720.52
5.5.350.0100.12020.45
5.5.340.0170.15320.91
5.5.330.0100.10320.99
5.5.320.0070.15720.91
5.5.310.0070.14720.83
5.5.300.0100.15321.02
5.5.290.0000.11021.01
5.5.280.0100.16021.02
5.5.270.0070.12320.96
5.5.260.0070.10320.98
5.5.250.0070.18720.75
5.5.240.0170.14020.23
5.5.230.0170.16320.40
5.5.220.0000.18020.38
5.5.210.0130.17720.36
5.5.200.0030.16020.39
5.5.190.0030.11720.23
5.5.180.0100.13720.23
5.5.160.0070.16020.35
5.5.150.0130.16320.38
5.5.140.0030.12720.37
5.5.130.0030.13720.25
5.5.120.0100.11020.10
5.5.110.0070.11320.38
5.5.100.0030.11720.07
5.5.90.0030.09720.13
5.5.80.0030.13020.24
5.5.70.0000.10020.25
5.5.60.0030.11320.20
5.5.50.0030.09720.23
5.5.40.0030.09720.25
5.5.30.0030.09720.17
5.5.20.0070.11320.16
5.5.10.0030.11020.08
5.5.00.0030.10020.22
5.4.450.0170.10319.43
5.4.440.0070.10319.48
5.4.430.0000.10719.26
5.4.420.0030.18019.58
5.4.410.0070.17319.42
5.4.400.0330.14718.95
5.4.390.0370.10719.20
5.4.380.0170.12319.12
5.4.370.0170.14019.12
5.4.360.0030.17319.30
5.4.350.0100.14319.07
5.4.340.0070.11319.27
5.4.320.0130.14018.92
5.4.310.0070.18019.09
5.4.300.0100.11019.11
5.4.290.0100.14719.02
5.4.280.0270.10019.01
5.4.270.0030.11719.09
5.4.260.0070.11319.23
5.4.250.0100.11019.16
5.4.240.0100.13719.06
5.4.230.0030.13319.23
5.4.220.0030.11319.22
5.4.210.0030.10019.22
5.4.200.0000.10719.14
5.4.190.0030.12319.25
5.4.180.0030.09319.07
5.4.170.0070.09019.09
5.4.160.0130.08719.23
5.4.150.0070.09019.08
5.4.140.0000.09716.51
5.4.130.0070.11716.61
5.4.120.0070.09716.53
5.4.110.0000.14016.55
5.4.100.0100.13316.55
5.4.90.0030.16716.51
5.4.80.0070.15016.48
5.4.70.0070.15716.61
5.4.60.0030.14716.61
5.4.50.0000.12716.44
5.4.40.0030.19016.53
5.4.30.0100.15016.46
5.4.20.0130.17016.56
5.4.10.0030.15716.53
5.4.00.0030.13716.06
5.3.290.0000.24014.86
5.3.280.0130.17314.83
5.3.270.0100.16314.88
5.3.260.0270.16314.82
5.3.250.0030.16314.79
5.3.240.0030.17714.76
5.3.230.0030.17314.82
5.3.220.0030.25014.86
5.3.210.0030.27014.86
5.3.200.0130.25014.77
5.3.190.0100.24714.84
5.3.180.0100.22014.74
5.3.170.0100.28314.86
5.3.160.0100.22714.87
5.3.150.0000.20014.86
5.3.140.0030.22014.82
5.3.130.0200.27314.84
5.3.120.0100.26714.75
5.3.110.0030.30714.71
5.3.100.0070.27014.29
5.3.90.0000.24014.21
5.3.80.0000.22014.24
5.3.70.0030.21314.16
5.3.60.0300.16014.23
5.3.50.0000.22714.06
5.3.40.0100.25314.18
5.3.30.0070.25714.10
5.3.20.0130.27713.75
5.3.10.0100.26313.76
5.3.00.0070.25713.72

preferences:
40.79 ms | 401 KiB | 5 Q