Last active
August 29, 2015 14:17
-
-
Save kaja47/fd426c8c21ddb07bb617 to your computer and use it in GitHub Desktop.
PHP puzzler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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