Skip to content

Instantly share code, notes, and snippets.

@kaja47
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaja47/fd426c8c21ddb07bb617 to your computer and use it in GitHub Desktop.
Save kaja47/fd426c8c21ddb07bb617 to your computer and use it in GitHub Desktop.
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