3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php define('N', 1000000); $h = array_fill(0, N, 0); function pushDown($pos, $n) { global $h; while (2 * $pos + 1 < $n) { $j = 2 * $pos + 1; if ($j + 1 < $n && $h[$j + 1] > $h[$j]) $j++; if ($h[$pos] >= $h[$j]) break; $t = $h[$pos]; $h[$pos] = $h[$j]; $h[$j] = $t; $pos = $j; } } function main() { global $h; $start = round(microtime(true) * 1000); for ($i = 0; $i < N; $i++) { $h[$i] = $i; } for ($i = (int) (N / 2); $i >= 0; $i--) { pushDown($i, N); } $n = N; while ($n > 1) { $n--; $t = $h[0]; $h[0] = $h[$n]; $h[$n] = $t; pushDown(0, $n); } foreach ($h as $i => $v) { if ($i !== $v) { echo "Sorting failed at index $i!\n"; return; } } $finish = round(microtime(true) * 1000); $delta = $finish - $start; echo "Done in $delta\n"; } main();
Output for 4.3.0 - 5.2.0, 7.0.12 - 7.1.0

Process exited with code 137.
Output for 7.0.10
Done in 2040
Output for 7.0.9
Done in 1971
Output for 7.0.8
Done in 1981
Output for 7.0.4, 7.0.7
Done in 1991
Output for 7.0.6
Done in 2019
Output for 7.0.5
Done in 2048
Output for 7.0.3
Done in 1885
Output for 7.0.2
Done in 1845
Output for 7.0.1
Done in 1975
Output for 7.0.0
Done in 2002
Output for 5.4.0 - 5.6.28
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 72 bytes) in /in/ZEJ60 on line 5
Process exited with code 255.
Output for 5.2.1 - 5.3.29
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 71 bytes) in /in/ZEJ60 on line 5
Process exited with code 255.