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.0130.59521.97
8.3.50.0170.60424.01
8.3.40.0200.54723.85
8.3.30.0200.57224.23
8.3.20.0100.30625.31
8.3.10.0030.30724.55
8.3.00.0100.28723.75
8.2.180.0170.57021.57
8.2.170.0230.57823.85
8.2.160.0200.54125.53
8.2.150.0130.33124.18
8.2.140.0130.32024.66
8.2.130.0130.33226.16
8.2.120.0000.33926.32
8.2.110.0200.51125.43
8.2.100.0130.39022.63
8.2.90.0100.39824.39
8.2.80.0130.41922.54
8.2.70.0000.41122.75
8.2.60.0070.39922.94
8.2.50.0070.39322.63
8.2.40.0070.38423.29
8.2.30.0070.36524.32
8.2.20.0100.38822.68
8.2.10.0100.39523.14
8.2.00.0100.39022.82
8.1.280.0030.57825.92
8.1.270.0100.34128.68
8.1.260.0100.32726.78
8.1.250.0100.31628.73
8.1.240.0030.53629.86
8.1.230.0130.39127.37
8.1.220.0130.40224.27
8.1.210.0070.40323.86
8.1.200.0030.40423.98
8.1.190.0130.39123.85
8.1.180.0130.40324.06
8.1.170.0070.38125.27
8.1.160.0000.37528.49
8.1.150.0130.40825.41
8.1.140.0030.40623.97
8.1.130.0070.38624.36
8.1.120.0030.38523.97
8.1.110.0030.41323.97
8.1.100.0030.41523.98
8.1.90.0100.45923.90
8.1.80.0070.38223.82
8.1.70.0030.39423.95
8.1.60.0070.52224.07
8.1.50.0130.52023.96
8.1.40.0070.52023.95
8.1.30.0070.52223.95
8.1.20.0100.51924.09
8.1.10.0030.52724.00
8.1.00.0070.51923.82
8.0.300.0030.37823.30
8.0.290.0000.41023.13
8.0.280.0070.40124.92
8.0.270.0070.40723.66
8.0.260.0000.40323.64
8.0.250.0030.39123.26
8.0.240.0070.39523.22
8.0.230.0130.38623.26
8.0.220.0130.39623.25
8.0.210.0070.38123.17
8.0.200.0000.43523.18
8.0.190.0100.52023.29
8.0.180.0130.51823.23
8.0.170.0130.51523.22
8.0.160.0100.52023.05
8.0.150.0030.52423.07
8.0.140.0070.52023.25
8.0.130.0070.52819.79
8.0.120.0100.51623.15
8.0.110.0130.51223.24
8.0.100.0070.52423.20
8.0.90.0100.51723.17
8.0.80.0210.78923.21
8.0.70.0220.73123.16
8.0.60.0130.77323.11
8.0.50.0130.72323.07
8.0.30.0250.75323.47
8.0.20.0250.73623.44
8.0.10.0230.79123.29
8.0.00.0260.70323.19
7.4.330.0030.46621.03
7.4.320.0100.43422.80
7.4.300.0030.44622.70
7.4.290.0070.56922.88
7.4.280.0000.58122.79
7.4.270.0030.57622.77
7.4.260.0100.56722.75
7.4.250.0030.57322.85
7.4.240.0030.57522.89
7.4.230.0070.56422.89
7.4.220.0131.00822.82
7.4.210.0110.93122.88
7.4.200.0160.82822.83
7.4.190.0300.89922.79
7.4.180.0230.87822.89
7.4.160.0150.80522.80
7.4.150.0230.82322.95
7.4.140.0320.84122.80
7.4.130.0250.81322.79
7.4.120.0270.87822.92
7.4.110.0210.81822.86
7.4.100.0200.77722.75
7.4.90.0200.86022.74
7.4.80.0360.93822.90
7.4.70.0261.02022.86
7.4.60.0230.89722.93
7.4.50.0100.64822.81
7.4.40.0160.83322.70
7.4.30.0770.72722.81
7.4.20.0230.77922.82
7.4.10.0230.83222.68
7.4.00.0100.88522.73
7.3.330.0130.67519.62
7.3.320.0070.59719.86
7.3.310.0100.60022.66
7.3.300.0100.60522.64
7.3.290.0190.97722.69
7.3.280.0231.09422.71
7.3.270.0211.02922.76
7.3.260.0321.05722.81
7.3.250.0210.97522.73
7.3.240.0230.99222.69
7.3.230.0200.97722.75
7.3.220.0250.95622.65
7.3.210.0280.97322.69
7.3.200.0191.01322.70
7.3.190.0240.94822.80
7.3.180.0160.99622.75
7.3.170.0281.01322.56
7.3.160.0260.97122.69
7.3.150.0161.06922.66
7.3.140.0361.03722.72
7.3.130.0260.95322.67
7.3.120.0230.95122.70
7.3.110.0160.89722.52
7.3.100.0260.92122.53
7.3.90.0220.94722.96
7.3.80.0291.07622.57
7.3.70.0260.90222.67
7.3.60.0160.93222.77
7.3.50.0161.11022.78
7.3.40.0221.07622.77
7.3.30.0260.89122.70
7.3.20.2740.81521.97
7.3.10.1520.79422.30
7.3.00.1740.78322.28
7.2.340.0270.97822.31
7.2.330.0200.99722.46
7.2.320.0471.15922.39
7.2.310.0261.05022.32
7.2.300.0260.94522.51
7.2.290.0230.93822.46
7.2.280.0261.05122.29
7.2.270.0161.07822.26
7.2.260.0400.95522.32
7.2.250.0330.96022.15
7.2.240.0230.93022.33
7.2.230.0231.08322.31
7.2.220.0401.01522.25
7.2.210.0430.86422.36
7.2.200.0260.90522.49
7.2.190.0330.95522.27
7.2.180.0270.91922.34
7.2.170.0260.94422.45
7.2.160.0230.91922.52
7.2.150.3600.83121.56
7.2.140.3130.82121.94
7.2.130.1730.86622.28
7.2.120.1510.86222.40
7.2.110.2210.90922.36
7.2.100.1300.81622.33
7.2.90.1910.86422.34
7.2.80.2010.85522.29
7.2.70.1590.81122.39
7.2.60.1560.80222.29
7.2.50.2340.85922.36
7.2.40.2140.82622.28
7.2.30.2310.85622.35
7.2.20.1850.86022.29
7.2.10.1850.78822.14
7.2.00.1820.78322.25
7.1.330.0321.16521.57
7.1.320.0301.15321.39
7.1.310.0521.57921.57
7.1.300.0301.15721.54
7.1.290.0361.31121.54
7.1.280.0261.06921.52
7.1.270.0451.20521.57
7.1.260.0561.17421.52
7.1.250.1851.24321.29
7.1.240.3280.91620.72
7.1.230.2650.88820.76
7.1.220.3200.88720.85
7.1.210.3670.92620.71
7.1.200.2610.87820.83
7.1.190.2810.87520.92
7.1.180.3860.83120.71
7.1.170.3460.90620.86
7.1.160.3610.86520.89
7.1.150.3330.86920.86
7.1.140.3280.86820.87
7.1.130.4120.87820.78
7.1.120.3560.86120.88
7.1.110.4000.81920.87
7.1.100.4230.80620.88
7.1.90.4270.90520.79
7.1.80.3000.81520.75
7.1.70.2810.83520.84
7.1.60.3050.89420.88
7.1.50.2610.87120.93
7.1.40.2250.86920.64
7.1.30.3340.90320.75
7.1.20.2700.86220.82
7.1.10.0431.13221.78
7.1.00.0261.08421.68
7.0.330.3160.96620.37
7.0.320.2811.00720.40
7.0.310.3360.91420.58
7.0.300.3440.91020.22
7.0.290.3610.90820.34
7.0.280.4110.88920.25
7.0.270.4280.93620.33
7.0.260.3980.96020.38
7.0.250.3890.95620.36
7.0.240.4200.95020.49
7.0.230.3150.92020.45
7.0.220.3080.92020.50
7.0.210.3230.90220.38
7.0.200.2860.84720.34
7.0.190.2910.86720.40
7.0.180.1940.89820.35
7.0.170.2940.93620.39
7.0.160.2890.93820.28
7.0.150.0331.16021.13
7.0.140.0351.23921.19
7.0.130.0331.20421.30
7.0.120.0231.14221.25
7.0.110.0361.12421.20
7.0.100.0191.16521.31
7.0.90.0461.17721.04
7.0.80.0261.10721.11
7.0.70.0301.22721.21
7.0.60.0401.18821.18
7.0.50.0171.17121.16
7.0.40.0461.13521.24
7.0.30.0291.13321.25
7.0.20.0361.20421.20
7.0.10.0401.14421.22
7.0.00.0261.11221.14
5.6.400.0331.96328.38
5.6.390.0201.98628.25
5.6.380.0381.89527.40
5.6.370.0251.85427.59
5.6.360.0361.77427.35
5.6.350.0361.75227.55
5.6.340.0381.83227.42
5.6.330.0431.80627.37
5.6.320.0251.76727.27
5.6.310.0381.93927.48
5.6.300.0451.94628.27
5.6.290.0451.96828.38
5.6.280.0491.94928.30
5.6.270.0431.96128.38
5.6.260.0331.96228.43
5.6.250.0261.97328.42
5.6.240.0261.97528.56
5.6.230.0431.96028.42
5.6.220.0431.95528.45
5.6.210.0431.95328.49
5.6.200.0331.97928.34
5.6.190.0231.98328.50
5.6.180.0431.95928.60
5.6.170.0431.95528.45
5.6.160.0201.98628.37
5.6.150.0361.95928.46
5.6.140.0361.96728.30
5.6.130.0461.95528.27
5.6.120.0261.98128.47
5.6.110.0301.98028.20
5.6.100.0261.97428.32
5.6.90.0331.97428.34
5.6.80.0431.95528.24
5.6.70.0271.98328.43
5.6.60.0201.98628.31
5.6.50.0201.98728.11
5.6.40.0531.95728.32
5.6.30.0491.94828.53
5.6.20.0431.96728.12
5.6.10.0392.06927.30
5.6.00.0472.00827.28
5.5.380.0431.95028.51
5.5.370.0201.98128.43
5.5.360.0591.94628.26
5.5.350.0431.95028.39
5.5.340.0361.96628.26
5.5.330.0331.96528.27
5.5.320.0301.95428.26
5.5.310.0431.95328.36
5.5.300.0481.93428.19
5.5.290.0621.92328.33
5.5.280.0491.94328.29
5.5.270.0291.95528.14
5.5.260.0501.97128.29
5.5.250.0331.96128.43
5.5.240.0331.96328.42
5.5.230.0491.92928.27
5.5.220.0331.95128.45
5.5.210.0331.96328.35
5.5.200.0291.94328.34
5.5.190.0591.94328.14
5.5.180.0451.93128.19
5.5.170.0281.97827.17
5.5.160.0561.95025.71
5.5.150.0301.98425.70
5.5.140.0432.02025.54
5.5.130.0261.97219.79
5.5.120.0262.15125.60
5.5.110.0391.92825.60
5.5.100.0352.05525.76
5.5.90.0342.14325.49
5.5.80.0392.13325.77
5.5.70.0442.14725.73
5.5.60.0452.03225.90
5.5.50.0472.00825.78
5.5.40.0282.09325.65
5.5.30.0462.03925.61
5.5.20.0362.04525.69
5.5.10.0302.07225.59
5.5.00.0351.99825.57
5.4.450.0361.96824.73
5.4.440.0391.95724.77
5.4.430.0391.95224.74
5.4.420.0331.96324.76
5.4.410.0481.97624.68
5.4.400.0201.98213.39
5.4.390.0331.97024.80
5.4.380.0391.95724.64
5.4.370.0361.96724.73
5.4.360.0331.96524.65
5.4.350.0391.95924.72
5.4.340.0391.96424.69
5.4.330.0312.04123.95
5.4.320.0521.92523.80
5.4.310.0332.07624.01
5.4.300.0361.97123.90
5.4.290.0392.17023.84
5.4.280.0362.13323.83
5.4.270.0392.09823.87
5.4.260.0371.95323.81
5.4.250.0322.00723.91
5.4.240.0392.16523.77
5.4.230.0462.02723.64
5.4.220.0402.00623.87
5.4.210.0382.16623.76
5.4.200.0402.03723.65
5.4.190.0432.18323.67
5.4.180.0442.13423.75
5.4.170.0322.06023.87
5.4.160.0262.02823.79
5.4.150.0252.10523.76
5.4.140.0361.99123.87
5.4.130.0432.02923.91
5.4.120.0282.11723.79
5.4.110.0452.00723.93
5.4.100.0332.12723.90
5.4.90.0271.94423.92
5.4.80.0451.89423.99
5.4.70.0491.90023.89
5.4.60.0382.08324.04
5.4.50.0302.13123.79
5.4.40.0392.00523.87
5.4.30.0362.08523.87
5.4.20.0412.16523.95
5.4.10.0262.15724.03
5.4.00.0252.09023.74

preferences:
43.08 ms | 401 KiB | 5 Q