Edit report at https://bugs.php.net/bug.php?id=37106&edit=1

 ID:                 37106
 Comment by:         scott dot baker at gmail dot com
 Reported by:        webmaster at polskabizuteria dot pl
 Summary:            uniqid() without  more_entropy extremally slow
 Status:             Not a bug
 Type:               Bug
 Package:            Performance problem
 Operating System:   *
 PHP Version:        *
 Block user comment: N
 Private report:     N

 New Comment:

$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


Previous Comments:
------------------------------------------------------------------------
[2006-05-28 12:34:05] he...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

uniqid() is meant to give you a certrain id distribuion that is not predicable. 
That is uniqid() must neither generate two identical ids nor have a constant or 
in any way predictable difference between two calls. To ensure this we use 
usleep() internally to either force a thread (windows) or process (*nix) 
switch. On some systems the operating system has a slow implementation of this. 
However distrubition this much more important than the security risks implied.

------------------------------------------------------------------------
[2006-04-17 14:52:45] 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);



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=37106&edit=1

Reply via email to