|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-04-17 14:52 UTC] webmaster at polskabizuteria dot pl
Description:
------------
Uniquid() without second parameter (more_entropy) set as true is extremaly slow (approx 500 times)
Reproduce code:
---------------
/* SLOW */
uniqid();
uniqid("");
uniqid("",false);
/* FAST */
uniqid("",true);
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 13:00:02 2025 UTC |
$loop = 10000; print "uniqid('') x $loop = " . bench('gen_uniqid',$loop) . " seconds<br />"; print "uniqid('',true) x $loop = " . bench('gen_uniqid_entropy',$loop) . " seconds<br />"; function gen_uniqid() { return uniqid(''); } function gen_uniqid_entropy() { return uniqid('',true); } function bench($func,$times) { $start = microtime(1); for ($i = 0; $i < $times; $i++) { call_user_func($func); } $end = microtime(1); $ret = sprintf("%0.4f",$end - $start); return $ret; } ------------------------------------------------------ uniqid('') x 10000 = 1.5876 seconds uniqid('',true) x 10000 = 0.0329 seconds Telling uniqid() to use more_entropy is MORE than 48 times faster