Guest User

Untitled

a guest
Apr 13th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1. <?php
  2.  
  3.     function foo(&$p) {
  4.         for($i=0; $i<count($p); $i++) {
  5.             // Do nothing  
  6.         }
  7.     }
  8.  
  9.     function foo2(&$p) {
  10.         $count = count($p);
  11.         for($i=0; $i<$count; $i++) {
  12.             // Do nothing  
  13.         }
  14.     }
  15.  
  16.     $array = array();
  17.  
  18.     for($i=0; $i<5000; $i++) {
  19.         $array[$i]=$i;
  20.     }
  21.  
  22.  
  23.     $t=microtime(true);
  24.     foo($array);
  25.     echo "Foo: " . (microtime(true)-$t) ."\n";
  26.  
  27.     $t=microtime(true);
  28.     foo2($array);
  29.     echo "Foo2: " . (microtime(true)-$t) ."\n";
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment