<?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.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
- 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.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
- 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 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Process exited with code 137.
preferences:
194.04 ms | 402 KiB | 325 Q