Created
May 5, 2015 12:21
-
-
Save Danack/00f0214c8e656567601f to your computer and use it in GitHub Desktop.
References rock
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
<?php | |
$numbers = []; | |
define('size', 10000); | |
for ($i=0 ; $i<size; $i++) { | |
$numbers[] = $i; | |
} | |
if (false) { | |
echo "Immutability sucks sometimes\n"; | |
function process($i, array $numbers) | |
{ | |
$index = rand(0, size - 1); | |
$tmp = $numbers[$index]; | |
$numbers[$index] = $numbers[$i]; | |
$numbers[$i] = $tmp; | |
return $numbers; | |
} | |
for ($i = 0; $i < size; $i++) { | |
$numbers = process($i, $numbers); | |
} | |
} | |
else { | |
echo "References rock sometimes\n"; | |
function process($i, array &$numbers) | |
{ | |
$index = rand(0, size - 1); | |
$tmp = $numbers[$index]; | |
$numbers[$index] = $numbers[$i]; | |
$numbers[$i] = $tmp; | |
} | |
for ($i = 0; $i < size; $i++) { | |
process($i, $numbers); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment