3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (function_exists("date_default_timezone_set")) { date_default_timezone_set("UTC"); } 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"; 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"); ?>

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.58422.48
8.3.50.0270.59824.10
8.3.40.0170.55223.76
8.3.30.0170.55424.08
8.3.20.0100.30425.26
8.3.10.0100.30324.72
8.3.00.0030.30023.66
8.2.180.0230.58821.54
8.2.170.0230.56823.86
8.2.160.0100.54525.59
8.2.150.0100.33224.25
8.2.140.0170.33224.66
8.2.130.0130.33426.16
8.2.120.0030.32526.23
8.2.110.0130.51725.43
8.2.100.0170.38623.25
8.2.90.0070.41624.29
8.2.80.0070.38922.54
8.2.70.0060.42422.30
8.2.60.0100.39222.84
8.2.50.0100.38622.54
8.2.40.0100.37923.14
8.2.30.0000.39423.21
8.2.20.0070.39322.71
8.2.10.0030.39923.14
8.2.00.0030.39122.82
8.1.280.0170.61725.92
8.1.270.0070.34830.07
8.1.260.0070.33328.74
8.1.250.0100.32928.09
8.1.240.0100.52730.02
8.1.230.0100.38925.59
8.1.220.0130.39324.16
8.1.210.0130.43223.90
8.1.200.0070.39523.85
8.1.190.0130.38823.86
8.1.180.0100.41224.03
8.1.170.0100.37825.08
8.1.160.0130.36328.48
8.1.150.0130.40825.35
8.1.140.0130.39223.97
8.1.130.0070.38224.40
8.1.120.0070.38523.82
8.1.110.0100.41023.90
8.1.100.0000.41723.96
8.1.90.0130.37423.93
8.1.80.0030.38923.96
8.1.70.0070.39423.99
8.1.60.0130.51524.03
8.1.50.0030.52223.99
8.1.40.0030.52623.87
8.1.30.0070.52523.89
8.1.20.0070.52024.06
8.1.10.0070.52223.93
8.1.00.0000.52423.95
8.0.300.0030.38823.60
8.0.290.0130.39523.13
8.0.280.0100.40124.83
8.0.270.0030.40323.55
8.0.260.0030.40523.67
8.0.250.0100.38223.29
8.0.240.0070.40123.28
8.0.230.0030.39523.16
8.0.220.0100.39823.11
8.0.210.0000.42023.18
8.0.200.0100.39623.31
8.0.190.0070.52723.21
8.0.180.0030.52623.23
8.0.170.0030.52423.32
8.0.160.0070.52223.18
8.0.150.0030.52723.14
8.0.140.0030.52023.04
8.0.130.0070.52019.79
8.0.120.0070.52223.18
8.0.110.0070.52223.17
8.0.100.0030.52223.19
8.0.90.0070.52323.04
8.0.80.0290.78023.19
8.0.70.0070.52323.26
8.0.60.0030.52223.17
8.0.50.0100.52023.23
8.0.30.0340.79223.32
8.0.20.0160.74923.21
8.0.10.0130.54023.23
8.0.00.0360.72023.20
7.4.330.0000.47121.11
7.4.320.0070.43422.78
7.4.300.0070.43422.76
7.4.290.0070.56922.88
7.4.280.0130.56822.78
7.4.270.0070.57522.88
7.4.260.0070.57122.76
7.4.250.0070.57522.76
7.4.240.0130.57922.78
7.4.230.0070.57022.90
7.4.220.0171.03822.64
7.4.210.0100.90322.92
7.4.200.0030.57322.94
7.4.160.0230.77622.82
7.4.150.0300.78822.92
7.4.140.0300.80122.74
7.4.130.0210.80022.98
7.4.120.0210.77122.89
7.4.110.0230.97222.77
7.4.100.0330.91222.74
7.4.90.0160.85322.76
7.4.80.0230.81222.98
7.4.70.0230.79722.89
7.4.60.0100.77322.90
7.4.50.0100.40722.73
7.4.40.0200.91822.90
7.4.30.0230.80522.78
7.4.00.0170.77321.38
7.3.330.0100.63619.80
7.3.320.0130.59719.63
7.3.310.0130.58822.70
7.3.300.0100.59222.68
7.3.290.0130.95822.64
7.3.280.0271.05422.67
7.3.270.0261.00122.70
7.3.260.0200.95722.79
7.3.250.0210.96522.82
7.3.240.0261.09122.72
7.3.230.0200.94022.67
7.3.210.0260.98222.88
7.3.200.0231.01322.74
7.3.190.0331.35522.86
7.3.180.0291.03522.63
7.3.170.0131.02922.79
7.3.160.0300.93522.67
7.2.330.0361.02422.57
7.2.320.0190.95222.52
7.2.310.0261.43322.79
7.2.300.0131.01622.69
7.2.290.0330.93822.29
7.2.60.0070.51422.65
7.2.00.0000.59125.61
7.1.200.0130.55321.89
7.1.100.0030.70024.36
7.1.70.0030.54323.14
7.1.60.0100.68323.09
7.1.50.0070.56122.85
7.0.200.0100.70822.92

preferences:
36.18 ms | 401 KiB | 5 Q