Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 17th, 2011  |  syntax: PHP  |  size: 0.64 KB  |  views: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3.  
  4. $initial = 5;
  5. $unit = 10;
  6. $operation = '+';
  7.  
  8. function add($a, $b) { return $a + $b; }
  9. function sub($a, $b) { return $a - $b; }
  10.  
  11. $operations = array('+' => 'add', '-' => 'sub');
  12.  
  13. $count = 100000;
  14. $start = microtime(true);
  15. for($i = 0; $i < $count; $i++)
  16.         $operations[$operation]($initial, $unit);
  17. $end = microtime(true);
  18.  
  19. echo "took " . number_format((($end - $start)/$count), 15) . " microseconds\n";
  20.  
  21. $start = microtime(true);
  22. $str = "return $initial $operation $unit;";
  23. for($i = 0; $i < $count; $i++)
  24.         eval($str);
  25. $end = microtime(true);
  26.  
  27. echo "took " . number_format((($end - $start)/$count), 15) . " microseconds\n";
  28.  
  29. ?>
clone this paste RAW Paste Data