Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHP puzzler
$size = 512*1024;
$keys = range(1, $size);
//shuffle($keys);
$arr = [];
foreach ($keys as $k) {
$arr[$k] = $k;
}
$s = microtime(1);
for ($round = 0; $round < 200; $round++) {
for ($i = 1; $i < $size; $i++) {
$arr[$i];
}
}
echo microtime(1) - $s, "\n";
// PHP 5
// without shuffle 4.7s
// with shuffle 14.1s
//
// PHP 7
// without shuffle 2.6s
// with shuffle 8.4s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.