Skip to content

Instantly share code, notes, and snippets.

@emaniacs
Created January 16, 2013 07:37
Show Gist options
  • Save emaniacs/4545317 to your computer and use it in GitHub Desktop.
Save emaniacs/4545317 to your computer and use it in GitHub Desktop.
Big integer random performance. Using rand() function and looping.
<?php
$t1Start = microtime(true);
$rand1 = rand(100000, 1000000);
$t1End = microtime(true);
//sleep(3);
$rand2 = '';
$length = 6;
$t2Start = microtime(true);
for ($x = 0; $x < $length; ++$x, $rand2.=rand(0,9));
$t2End = microtime(true);
echo 'First Random: Value(', $rand1, '), Start(', $t1Start, '), End(', $t1End, '), Diff(', ($t1End-$t1Start), ")\n";
echo 'Second Random: Value(', $rand2, '), Start(', $t2Start, '), End(', $t2End, '), Diff(', ($t2End-$t2Start), ")\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment