3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php define('N', 10000000); $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 7.0.0 - 7.1.0
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 536870920 bytes) in /in/NM2Bp on line 5
Process exited with code 255.
Output for 5.3.0 - 5.6.28
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 134217728 bytes) in /in/NM2Bp on line 5
Process exited with code 255.
Output for 5.2.1 - 5.2.17
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 71 bytes) in /in/NM2Bp on line 5
Process exited with code 255.
Output for 5.2.0
Fatal error: Out of memory (allocated 266076160) (tried to allocate 71 bytes) in /in/NM2Bp on line 5
Process exited with code 255.
Output for 4.3.0 - 5.1.6

Process exited with code 137.