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.0101.12716.88
8.3.50.0181.06817.48
8.3.40.0101.11319.26
8.3.30.0101.16919.09
8.3.20.0000.59719.15
8.3.10.0030.57120.82
8.3.00.0100.58519.63
8.2.180.0101.07516.75
8.2.170.0131.08822.96
8.2.160.0131.11721.17
8.2.150.0070.61624.18
8.2.140.0030.63424.66
8.2.130.0070.58826.16
8.2.120.0000.62019.61
8.2.110.0100.99721.03
8.2.100.0070.75718.22
8.2.90.0000.72519.41
8.2.80.0100.73017.97
8.2.70.0130.80017.75
8.2.60.0130.77518.28
8.2.50.0000.73718.07
8.2.40.0000.74318.30
8.2.30.0070.85518.47
8.2.20.0030.73817.97
8.2.10.0030.75717.99
8.2.00.0070.74817.90
8.1.280.0131.10025.92
8.1.270.0030.59224.66
8.1.260.0030.58226.35
8.1.250.0030.59528.09
8.1.240.0030.99121.54
8.1.230.0030.74117.64
8.1.220.0000.75117.91
8.1.210.0030.74118.77
8.1.200.0100.75117.72
8.1.190.0100.72117.60
8.1.180.0030.72618.10
8.1.170.0030.72619.02
8.1.160.0030.74219.15
8.1.150.0030.72319.02
8.1.140.0030.74317.77
8.1.130.0000.74318.08
8.1.120.0030.75417.73
8.1.110.0000.73417.80
8.1.100.0130.73117.75
8.1.90.0030.74117.82
8.1.80.0000.77117.69
8.1.70.0000.76017.74
8.1.60.0071.04817.86
8.1.50.0031.03217.77
8.1.40.0001.03417.82
8.1.30.0031.03917.93
8.1.20.0001.05117.93
8.1.10.0001.04817.82
8.1.00.0031.03617.92
8.0.300.0030.74518.77
8.0.290.0030.76717.00
8.0.280.0000.75418.70
8.0.270.0030.74617.11
8.0.260.0030.76917.15
8.0.250.0000.76617.29
8.0.240.0030.76117.25
8.0.230.0000.82217.30
8.0.220.0070.78417.24
8.0.210.0070.79317.27
8.0.200.0030.79217.26
8.0.190.0071.04517.30
8.0.180.0001.05617.28
8.0.170.0031.05817.29
8.0.160.0001.04717.27
8.0.150.0071.04917.07
8.0.140.0131.09317.19
8.0.130.0031.05213.61
8.0.120.0001.06117.15
8.0.110.0031.05417.17
8.0.100.0001.06117.17
8.0.90.0031.05417.03
8.0.80.0131.40617.27
8.0.70.0071.03717.24
8.0.60.0131.06817.24
8.0.50.0001.08417.11
8.0.30.0191.33217.52
8.0.20.0101.54217.51
8.0.10.0101.06717.40
8.0.00.0301.59917.03
7.4.330.0060.85213.24
7.4.320.0000.84716.72
7.4.300.0000.84816.75
7.4.290.0071.15916.70
7.4.280.0101.20216.82
7.4.270.0031.16016.88
7.4.260.0031.17113.46
7.4.250.0101.20316.65
7.4.240.0101.16116.75
7.4.230.0071.17116.65
7.4.220.0231.80316.68
7.4.210.0151.50216.84
7.4.200.0001.16816.93
7.4.190.0031.16016.72
7.4.160.0101.38216.95
7.4.150.0191.49016.72
7.4.140.0181.60616.88
7.4.130.0101.49616.84
7.4.120.0161.43516.84
7.4.110.0061.54316.73
7.4.100.0061.47316.61
7.4.90.0131.68516.62
7.4.80.0161.63617.00
7.4.70.0251.80016.65
7.4.60.0380.64916.71
7.4.50.0070.90416.39
7.4.40.0071.28816.48
7.4.30.0071.48216.91
7.3.330.0031.27813.45
7.3.320.0131.42513.54
7.3.310.0031.24016.61
7.3.300.0101.26116.55
7.3.290.0161.76116.64
7.3.280.0171.88516.61
7.3.270.0231.51916.66
7.3.260.0161.62116.50
7.3.250.0291.82716.76
7.3.240.0071.69116.72
7.3.230.0101.59516.63
7.3.210.0161.63316.80
7.3.200.0131.89319.39
7.3.190.0132.08016.88
7.3.180.0161.53816.77
7.3.170.0061.62116.77
7.3.160.0132.43716.84
7.2.330.0161.86817.13
7.2.320.0031.81317.16
7.2.310.0162.32017.03
7.2.300.0202.16117.15
7.2.290.0131.82117.09
7.2.100.1361.42714.87
7.2.90.1091.37915.14
7.2.80.0791.49615.30
7.2.70.1051.36215.16
7.2.60.0391.38414.89
7.2.50.0471.07515.22
7.1.220.1601.61213.95
7.1.210.1251.53814.27
7.1.200.0411.61114.35
7.1.190.0191.55813.93
7.1.180.0701.19614.00
7.1.170.0251.04814.13
7.0.310.0161.60713.62
7.0.300.0280.99513.71
5.6.380.0372.15714.13
5.6.370.0251.78614.52
5.6.360.0280.90414.34

preferences:
52.94 ms | 401 KiB | 5 Q