3v4l.org

run code in 300+ PHP versions simultaneously
<?php //date_default_timezone_set('UTC'); set_time_limit(120); ini_set('max_execution_time', 120); echo "PHP VERSION: ".PHP_VERSION."\n"; function simple() { $a = 0; for ($i = 0; $i < 1000000; $i++) $a++; $thisisanotherlongname = 0; for ($thisisalongname = 0; $thisisalongname < 1000000; $thisisalongname++) $thisisanotherlongname++; } /****/ function simplecall() { for ($i = 0; $i < 1000000; $i++) strlen("hallo"); } /****/ function hallo($a) { } function simpleucall() { for ($i = 0; $i < 1000000; $i++) hallo("hallo"); } /****/ function simpleudcall() { for ($i = 0; $i < 1000000; $i++) hallo2("hallo"); } function hallo2($a) { } /****/ function mandel() { $w1=50; $h1=150; $recen=-.45; $imcen=0.0; $r=0.7; $s=0; $rec=0; $imc=0; $re=0; $im=0; $re2=0; $im2=0; $x=0; $y=0; $w2=0; $h2=0; $color=0; $s=2*$r/$w1; $w2=40; $h2=12; for ($y=0 ; $y<=$w1; $y=$y+1) { $imc=$s*($y-$h2)+$imcen; for ($x=0 ; $x<=$h1; $x=$x+1) { $rec=$s*($x-$w2)+$recen; $re=$rec; $im=$imc; $color=1000; $re2=$re*$re; $im2=$im*$im; while( ((($re2+$im2)<1000000) && $color>0)) { $im=$re*$im*2+$imc; $re=$re2-$im2+$rec; $re2=$re*$re; $im2=$im*$im; $color=$color-1; } if ( $color==0 ) { print "_"; } else { print "#"; } } print "<br>"; flush(); } } /****/ function mandel2() { $b = " .:,;!/>)|&IH%*#"; //float r, i, z, Z, t, c, C; for ($y=30; printf("\n"), $C = $y*0.1 - 1.5, $y--;){ for ($x=0; $c = $x*0.04 - 2, $z=0, $Z=0, $x++ < 75;){ for ($r=$c, $i=$C, $k=0; $t = $z*$z - $Z*$Z + $r, $Z = 2*$z*$Z + $i, $z=$t, $k<5000; $k++) if ($z*$z + $Z*$Z > 500000) break; echo $b[$k%16]; } } } /****/ function Ack($m, $n){ if($m == 0) return $n+1; if($n == 0) return Ack($m-1, 1); return Ack($m - 1, Ack($m, ($n - 1))); } function ackermann($n) { $r = Ack(3,$n); print "Ack(3,$n): $r\n"; } /****/ function ary($n) { for ($i=0; $i<$n; $i++) { $X[$i] = $i; } for ($i=$n-1; $i>=0; $i--) { $Y[$i] = $X[$i]; } $last = $n-1; print "$Y[$last]\n"; } /****/ function ary2($n) { for ($i=0; $i<$n;) { $X[$i] = $i; ++$i; $X[$i] = $i; ++$i; $X[$i] = $i; ++$i; $X[$i] = $i; ++$i; $X[$i] = $i; ++$i; $X[$i] = $i; ++$i; $X[$i] = $i; ++$i; $X[$i] = $i; ++$i; $X[$i] = $i; ++$i; $X[$i] = $i; ++$i; } for ($i=$n-1; $i>=0;) { $Y[$i] = $X[$i]; --$i; $Y[$i] = $X[$i]; --$i; $Y[$i] = $X[$i]; --$i; $Y[$i] = $X[$i]; --$i; $Y[$i] = $X[$i]; --$i; $Y[$i] = $X[$i]; --$i; $Y[$i] = $X[$i]; --$i; $Y[$i] = $X[$i]; --$i; $Y[$i] = $X[$i]; --$i; $Y[$i] = $X[$i]; --$i; } $last = $n-1; print "$Y[$last]\n"; } /****/ function ary3($n) { for ($i=0; $i<$n; $i++) { $X[$i] = $i + 1; $Y[$i] = 0; } for ($k=0; $k<1000; $k++) { for ($i=$n-1; $i>=0; $i--) { $Y[$i] += $X[$i]; } } $last = $n-1; print "$Y[0] $Y[$last]\n"; } /****/ function fibo_r($n){ return(($n < 2) ? 1 : fibo_r($n - 2) + fibo_r($n - 1)); } function fibo($n) { $r = fibo_r($n); print "$r\n"; } /****/ function hash1($n) { for ($i = 1; $i <= $n; $i++) { $X[dechex($i)] = $i; } $c = 0; for ($i = $n; $i > 0; $i--) { if ($X[dechex($i)]) { $c++; } } print "$c\n"; } /****/ function hash2($n) { for ($i = 0; $i < $n; $i++) { $hash1["foo_$i"] = $i; $hash2["foo_$i"] = 0; } for ($i = $n; $i > 0; $i--) { foreach($hash1 as $key => $value) $hash2[$key] += $value; } $first = "foo_0"; $last = "foo_".($n-1); print "$hash1[$first] $hash1[$last] $hash2[$first] $hash2[$last]\n"; } /****/ function gen_random ($n) { global $LAST; return( ($n * ($LAST = ($LAST * IA + IC) % IM)) / IM ); } function heapsort_r($n, &$ra) { $l = ($n >> 1) + 1; $ir = $n; while (1) { if ($l > 1) { $rra = $ra[--$l]; } else { $rra = $ra[$ir]; $ra[$ir] = $ra[1]; if (--$ir == 1) { $ra[1] = $rra; return; } } $i = $l; $j = $l << 1; while ($j <= $ir) { if (($j < $ir) && ($ra[$j] < $ra[$j+1])) { $j++; } if ($rra < $ra[$j]) { $ra[$i] = $ra[$j]; $j += ($i = $j); } else { $j = $ir + 1; } } $ra[$i] = $rra; } } function heapsort($N) { global $LAST; define("IM", 139968); define("IA", 3877); define("IC", 29573); $LAST = 42; for ($i=1; $i<=$N; $i++) { $ary[$i] = gen_random(1); } heapsort_r($N, $ary); printf("%.10f\n", $ary[$N]); } /****/ function mkmatrix ($rows, $cols) { $count = 1; $mx = array(); for ($i=0; $i<$rows; $i++) { for ($j=0; $j<$cols; $j++) { $mx[$i][$j] = $count++; } } return($mx); } function mmult ($rows, $cols, $m1, $m2) { $m3 = array(); for ($i=0; $i<$rows; $i++) { for ($j=0; $j<$cols; $j++) { $x = 0; for ($k=0; $k<$cols; $k++) { $x += $m1[$i][$k] * $m2[$k][$j]; } $m3[$i][$j] = $x; } } return($m3); } function matrix($n) { $SIZE = 30; $m1 = mkmatrix($SIZE, $SIZE); $m2 = mkmatrix($SIZE, $SIZE); while ($n--) { $mm = mmult($SIZE, $SIZE, $m1, $m2); } print "{$mm[0][0]} {$mm[2][3]} {$mm[3][2]} {$mm[4][4]}\n"; } /****/ function nestedloop($n) { $x = 0; for ($a=0; $a<$n; $a++) for ($b=0; $b<$n; $b++) for ($c=0; $c<$n; $c++) for ($d=0; $d<$n; $d++) for ($e=0; $e<$n; $e++) for ($f=0; $f<$n; $f++) $x++; print "$x\n"; } /****/ function sieve($n) { $count = 0; while ($n-- > 0) { $count = 0; $flags = range (0,8192); for ($i=2; $i<8193; $i++) { if ($flags[$i] > 0) { for ($k=$i+$i; $k <= 8192; $k+=$i) { $flags[$k] = 0; } $count++; } } } print "Count: $count\n"; } /****/ function strcat($n) { $str = ""; while ($n-- > 0) { $str .= "hello\n"; } $len = strlen($str); print "$len\n"; } /*****/ function getmicrotime() { $t = gettimeofday(); return ($t['sec'] + $t['usec'] / 1000000); } function start_test() { ob_start(); return getmicrotime(); } function end_test($start, $name) { global $total; $end = getmicrotime(); ob_end_clean(); $total += $end-$start; $num = number_format($end-$start,3); $pad = str_repeat(" ", 24-strlen($name)-strlen($num)); echo $name.$pad.$num."\n"; // flush(); 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"; } $t0 = $t = start_test(); simple(); $t = end_test($t, "simple"); simplecall(); $t = end_test($t, "simplecall"); simpleucall(); $t = end_test($t, "simpleucall"); simpleudcall(); $t = end_test($t, "simpleudcall"); mandel(); $t = end_test($t, "mandel"); mandel2(); $t = end_test($t, "mandel2"); ackermann(7); $t = end_test($t, "ackermann(7)"); ary(50000); $t = end_test($t, "ary(50000)"); ary2(50000); $t = end_test($t, "ary2(50000)"); ary3(2000); $t = end_test($t, "ary3(2000)"); fibo(30); $t = end_test($t, "fibo(30)"); hash1(50000); $t = end_test($t, "hash1(50000)"); hash2(500); $t = end_test($t, "hash2(500)"); heapsort(20000); $t = end_test($t, "heapsort(20000)"); matrix(20); $t = end_test($t, "matrix(20)"); nestedloop(12); $t = end_test($t, "nestedloop(12)"); sieve(30); $t = end_test($t, "sieve(30)"); strcat(200000); $t = end_test($t, "strcat(200000)"); total($t0, "Total"); echo 'Memory (MB): '.( (function_exists('memory_get_usage')) ? number_format(memory_get_usage()/1024/1024, 2) : '-' );

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)
7.3.00.1480.70922.07
7.2.130.1260.77622.00
7.2.120.0850.74921.76
7.2.110.1210.77422.06
7.2.100.1690.85221.76
7.2.90.1470.79722.03
7.2.80.1600.78621.82
7.2.70.1690.79422.09
7.2.60.2390.78622.08
7.2.50.2510.90521.91
7.2.40.1510.77822.01
7.2.30.1670.89221.94
7.2.20.1560.80322.06
7.2.10.2040.80021.96
7.2.00.0850.67323.11
7.1.250.1761.18020.98
7.1.240.1281.16421.01
7.1.230.1471.17620.83
7.1.220.1761.13721.00
7.1.210.1611.18720.78
7.1.200.1741.13120.69
7.1.190.2641.19920.58
7.1.180.2271.19520.70
7.1.170.1871.19820.60
7.1.160.1511.21020.88
7.1.150.1761.17420.83
7.1.140.1441.16120.86
7.1.130.1961.19220.83
7.1.120.1531.23820.80
7.1.110.2181.26920.91
7.1.100.1621.18420.65
7.1.90.1811.14820.90
7.1.80.2141.13720.85
7.1.70.1290.94821.75
7.1.60.1230.99821.68
7.1.50.1110.96921.34
7.1.40.1281.14020.84
7.1.30.1281.19220.73
7.1.20.2091.17420.88
7.1.10.0001.74021.66
7.1.00.0071.69921.72
7.0.330.1431.19920.62
7.0.320.1741.19920.56
7.0.310.1811.17920.62
7.0.300.1781.18220.62
7.0.290.2031.20620.33
7.0.280.1781.21420.61
7.0.270.1531.17720.46
7.0.260.3011.19820.45
7.0.250.2101.23420.36
7.0.240.1161.22920.72
7.0.230.2441.19420.74
7.0.220.2231.22920.52
7.0.210.1571.20120.44
7.0.200.1051.04721.33
7.0.190.2361.26420.59
7.0.180.1261.27620.49
7.0.170.1891.23520.58
7.0.160.1831.22220.63
7.0.150.0101.75921.59
7.0.140.0001.79321.48
7.0.130.0031.70821.71
7.0.120.0031.75421.75
7.0.110.0031.70021.44
7.0.100.0071.72421.28
7.0.90.0071.74421.65
7.0.80.0131.74121.67
7.0.70.0031.80821.46
7.0.60.0031.88121.49
7.0.50.0031.77021.64
7.0.40.0071.70017.46
7.0.30.0031.65517.60
7.0.20.0071.72917.46
7.0.10.0031.72917.66
7.0.00.0071.71217.63
5.6.380.0332.25126.54
5.6.370.0282.18026.30
5.6.360.0242.20026.17
5.6.350.0352.26326.29
5.6.340.0252.24626.46
5.6.330.0172.19126.28
5.6.320.0332.16326.67
5.6.310.0332.23326.58
5.6.300.0172.47926.26
5.6.290.0102.48226.43
5.6.280.0102.48826.77
5.6.270.0232.41426.61
5.6.260.0132.48226.39
5.6.250.0072.49026.42
5.6.240.0132.44826.52
5.6.230.0102.45426.66
5.6.220.0132.47526.57
5.6.210.0072.46926.35
5.6.200.0072.47526.25
5.6.190.0172.47926.44
5.6.180.0202.46526.50
5.6.170.0202.47626.50
5.6.160.0032.48526.32
5.6.150.0202.44326.42
5.6.140.0102.47726.25
5.6.130.0132.48326.63
5.6.120.0172.45926.60
5.6.110.0232.40826.63
5.6.100.0102.47326.37
5.6.90.0072.48826.50
5.6.80.0132.48326.69
5.6.70.0202.45526.71
5.6.60.0102.48726.40
5.6.50.0102.46126.71
5.6.40.0262.46626.66
5.6.30.0532.43626.72
5.6.20.0532.41926.17
5.6.10.0402.37626.20
5.6.00.0432.43526.37
5.5.380.0132.48123.29
5.5.370.0102.48823.34
5.5.360.0202.47023.41
5.5.350.0072.48823.41
5.5.340.0132.48123.29
5.5.330.0072.48223.27
5.5.320.0132.47523.12
5.5.310.0102.48723.29
5.5.300.0172.44723.05
5.5.290.0102.47423.31
5.5.280.0172.45723.27
5.5.270.0202.47623.13
5.5.260.0072.49122.91
5.5.250.0102.48623.18
5.5.240.0202.43623.35
5.5.230.0102.48523.26
5.5.220.0232.47223.28
5.5.210.0232.47123.24
5.5.200.0272.45223.27
5.5.190.0202.47723.20
5.5.180.0072.44823.01
5.5.170.0362.40423.10
5.5.160.0172.43823.40
5.5.150.0432.29123.36
5.5.140.0432.27222.84
5.5.130.0402.42423.16
5.5.120.0372.32123.32
5.5.110.0632.33923.26
5.5.100.0532.40723.13
5.5.90.0302.33623.34
5.5.80.0402.38322.78
5.5.70.0432.27723.39
5.5.60.0572.35422.91
5.5.50.0332.41423.30
5.5.40.0272.42023.29
5.5.30.0332.43523.07
5.5.20.0072.41823.00
5.5.10.0272.42423.37
5.5.00.0272.41322.92
5.4.450.0272.46723.34
5.4.440.0102.48523.00
5.4.430.0172.40723.18
5.4.420.0102.47223.21
5.4.410.0102.41623.15
5.4.400.0172.43023.21
5.4.390.0032.34722.85
5.4.380.0232.42823.22
5.4.370.0302.36523.20
5.4.360.0132.41523.15
5.4.350.0272.39923.25
5.4.340.0582.22823.22
5.4.330.0432.34822.77
5.4.320.0402.35623.02
5.4.310.0402.39022.92
5.4.300.0172.44323.13
5.4.290.0502.38222.86
5.4.280.0302.40723.04
5.4.270.0372.41223.06
5.4.260.0472.42722.79
5.4.250.0742.27523.34
5.4.240.0302.42423.16
5.4.230.0532.25322.90
5.4.220.0332.42723.32
5.4.210.0372.37023.11
5.4.200.0332.43123.13
5.4.190.0402.44123.03
5.4.180.0302.43723.15
5.4.170.0272.42523.09
5.4.160.0172.44522.91
5.4.150.0402.41322.98
5.4.140.0432.35923.14
5.4.130.0432.40922.92
5.4.120.0432.43623.17
5.4.110.0372.42222.99
5.4.100.0462.39523.14
5.4.90.0632.37723.16
5.4.80.0412.39223.30
5.4.70.0332.41923.17
5.4.60.0402.41823.26
5.4.50.0302.42622.77
5.4.40.0372.45023.08
5.4.30.0272.42123.36
5.4.20.0232.44123.16
5.4.10.0362.39123.25
5.4.00.0272.41323.24
5.3.290.0002.36311.18
5.3.280.0032.47611.18
5.3.270.0062.43311.18
5.3.260.0032.47711.18
5.3.250.0032.39011.18
5.3.240.0102.48911.18
5.3.230.0102.41211.18
5.3.220.0102.31711.18
5.3.210.0032.42811.18
5.3.200.0002.47311.18
5.3.190.0002.46711.18
5.3.180.0132.44011.18
5.3.170.0032.46611.18
5.3.160.0002.42711.18
5.3.150.0102.45711.18
5.3.140.0002.41911.18
5.3.130.0032.43011.18
5.3.120.0032.45611.18
5.3.110.0092.45711.18
5.3.100.0032.42111.18
5.3.90.0072.38411.18
5.3.80.0002.49511.18
5.3.70.0072.33911.18
5.3.60.0032.44111.18
5.3.50.0072.47211.18
5.3.40.0002.44811.18
5.3.30.0102.49011.18
5.3.20.0072.41311.18
5.3.10.0072.49111.18
5.3.00.0072.49011.18

preferences:
51.81 ms | 401 KiB | 5 Q