Last active
January 4, 2016 03:33
-
-
Save carcinocron/e09ef8b98aa809880c07 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
<pre><?php | |
/** | |
The goal is fast + unique, this is not for cryptographically secure purposes! | |
*/ | |
define('LOOP_COUNT',100000); | |
define() | |
$startTime = microtime(true); | |
for($x=0;$x<LOOP_COUNT;$x++) | |
{ | |
// Your content to test | |
$var =mt_rand(100000000000000,999999999999999); | |
} | |
$endTime = microtime(true); | |
$elapsed = $endTime - $startTime; | |
echo 'mt_rand in: ',$elapsed,"\n"; | |
$startTime = microtime(true); | |
for($x=0;$x<LOOP_COUNT;$x++) | |
{ | |
// Your content to test | |
$var = openssl_random_pseudo_bytes(14); | |
} | |
$endTime = microtime(true); | |
$elapsed = $endTime - $startTime; | |
echo 'openssl_random_pseudo_bytes(14): in ',$elapsed,"\n"; | |
$startTime = microtime(true); | |
for($x=0;$x< LOOP_COUNT;$x++) | |
{ | |
// Your content to test | |
$var = uniqid('',true); | |
} | |
$endTime = microtime(true); | |
$elapsed = $endTime - $startTime; | |
echo 'uniqid(\'\',true) in: ',$elapsed,"\n"; | |
$startTime = microtime(true); | |
for($x=0;$x< LOOP_COUNT;$x++) | |
{ | |
// Your content to test | |
$var = uniqid('',false); | |
} | |
$endTime = microtime(true); | |
$elapsed = $endTime - $startTime; | |
echo 'uniqid(\'\',false) in: ',$elapsed,"\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my laptop, single threaded: