Advertisement
Guest User

PHP Quote Times

a guest
Nov 28th, 2011
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. define('NUM_EXECUTIONS', 100000);
  4.  
  5. function timeFunc($function, $runs)
  6. {
  7.   $times = array();
  8.  
  9.   for ($i = 0; $i < $runs; $i++)
  10.   {
  11.     $time = microtime();
  12.     call_user_func($function);
  13.     $times[$i] = microtime() - $time;
  14.   }
  15.  
  16.   return array_sum($times) / $runs;
  17. }
  18.  
  19. function Method1()
  20. {
  21.   $foo = 'some words';
  22.   for ($i = 0; $i < NUM_EXECUTIONS; $i++)
  23.     $t = "these are 1";
  24. }
  25.  
  26. function Method2()
  27.  {
  28.   $foo = 'some words';
  29.   for ($i = 0; $i < NUM_EXECUTIONS; $i++)
  30.     $t = "these are " . $foo;
  31. }
  32.  
  33. function Method3()
  34. {
  35.   $foo = 'some words';
  36.   for ($i = 0; $i < NUM_EXECUTIONS; $i++)
  37.     $t = "these are $foo";
  38. }
  39.  
  40. function Method4()
  41. {
  42.   $foo = 'some words';
  43.   for ($i = 0; $i < NUM_EXECUTIONS; $i++)
  44.     $t = "these are {$foo}";
  45. }
  46.  
  47. print timeFunc('Method1', 10) . "\n";
  48. print timeFunc('Method2', 10) . "\n";
  49. print timeFunc('Method3', 10) . "\n";
  50. print timeFunc('Method4', 10) . "\n";
  51.  
  52. ?>
  53.  
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement