Guest User

Untitled

a guest
Mar 14th, 2012
59
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $str = "abcdefg";
  4. $length = strlen($str);
  5.  
  6.  
  7. $start = microtime(true);
  8. for ($m = 1000000; $m > 0; $m--) {
  9.     for ($i = 0; $i < $length; $i++)
  10.     {
  11.         $a = 2*$i;
  12.     }
  13. }
  14. echo "with strlen precalculated: " . (microtime(true) - $start) . "\n";
  15.  
  16.  
  17. $start = microtime(true);
  18. for ($m = 1000000; $m > 0; $m--) {
  19.     for ($i = 0; $i < strlen($str); $i++)
  20.     {
  21.         $a = 2*$i;
  22.     }
  23. }
  24. echo "with strlen in the loop: " . (microtime(true) - $start) . "\n";
RAW Paste Data