maLakai

for_vs_fill_02_fill

Mar 18th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. $nTimes = 100000;
  2.  
  3. function microtime_float() {
  4.   list($usec, $sec) = explode(' ', microtime());
  5.   return ((float)$usec + (float)$sec);
  6. }
  7.  
  8. $smem = memory_get_usage();
  9. $stime = microtime_float();
  10.  
  11. $i = 0;
  12. while ($i < $nTimes) {
  13.   $aFill = array();
  14.   $aFill = array_fill(0, 10, mt_rand());
  15.   unset($aFill);
  16.   $i++;
  17. }
  18.  
  19. $etime = microtime_float();
  20. $emem = memory_get_usage();
  21. $time = $etime - $stime;
  22. $mem = $emem - $smem;
  23.  
  24. echo 'array_fill ran ' . $nTimes . ' times: ' . $time . ' seconds, mem: ' . $mem . ".\n";
Advertisement
Add Comment
Please, Sign In to add comment