-
-
Save nikic/5d44cb5d0d7c1f414f455090a0193567 to your computer and use it in GitHub Desktop.
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 | |
$numElems = 100000; | |
$numRepeats = 100; | |
foreach ([0.0, 0.01, 0.05, 0.1, 0.2, 0.5, 1.0] as $duplicateFraction) { | |
echo "$duplicateFraction: "; | |
$uniqueElems = (int) round($numElems * (1 - $duplicateFraction)); | |
$origArray = array_pad(range(0, $uniqueElems), $numElems, 0); | |
$t = microtime(true); | |
for ($i = 0; $i < $numRepeats; $i++) { | |
$array = $origArray; | |
shuffle($array); | |
sort($array); | |
} | |
var_dump(microtime(true) - $t); | |
} |
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
UNSTABLE | |
0.00: float(1.5692839622497559) | |
0.01: float(1.572052001953125) | |
0.05: float(1.5424528121948242) | |
0.10: float(1.5431289672851562) | |
0.20: float(1.4708871841430664) | |
0.50: float(1.2815279960632324) | |
1.00: float(0.9397969245910645) | |
STABLE | |
0.00: float(1.5857720375061035) | |
0.01: float(1.577707052230835) | |
0.05: float(1.581636905670166) | |
0.10: float(1.588440179824829) | |
0.20: float(1.600801944732666) | |
0.50: float(1.5892488956451416) | |
1.00: float(1.0026319026947021) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment