Skip to content

Instantly share code, notes, and snippets.

@Danack
Created May 5, 2015 12:21
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 Danack/00f0214c8e656567601f to your computer and use it in GitHub Desktop.
Save Danack/00f0214c8e656567601f to your computer and use it in GitHub Desktop.
References rock
<?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