Advertisement
Guest User

Untitled

a guest
Jan 11th, 2011
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. $quant = 15;
  2. $repeat = 10000;
  3.  
  4. $results[1] = array(); // results of first function
  5. $results[2] = array(); // results of second function
  6.  
  7. $b = null;
  8.  
  9. # Durchlauf
  10. for($c=1; $c<=$quant*2; $c++){
  11.   $time['start'] = microtime(true);
  12.   if($c%2) // 1,3,5,...
  13.     for($i=0; $i<$repeat; $i++){
  14.       # first Function
  15.       is_null($b);
  16.       is_null($b);
  17.       is_null($b);
  18.       is_null($b);
  19.       is_null($b);
  20.       is_null($b);
  21.       is_null($b);
  22.       is_null($b);
  23.       is_null($b);
  24.       is_null($b);
  25.       is_null($b);
  26.       is_null($b);
  27.     }
  28.   else // 2,4,6,...
  29.     for($i=0; $i<$repeat; $i++){
  30.       # second Function
  31.       $b===NULL;
  32.       $b===NULL;
  33.       $b===NULL;
  34.       $b===NULL;
  35.       $b===NULL;
  36.       $b===NULL;
  37.       $b===NULL;
  38.       $b===NULL;
  39.       $b===NULL;
  40.       $b===NULL;
  41.       $b===NULL;
  42.       $b===NULL;
  43.     }
  44.   $time['end'] = microtime(true);
  45.   $results[!($c%2)+1][] = $time['end']-$time['start'];
  46. }
  47.  
  48.  
  49. $leerlaufres = array(); // results of empty for()-loop
  50. for($c=1; $c<=$quant*2; $c++){ # Leerlauf messen
  51.  $time['start'] = microtime(true);
  52.   if($c%2) // 1,3,5,...
  53.     for($i=0; $i<$repeat; $i++){}
  54.   else // 2,4,6,...
  55.     for($i=0; $i<$repeat; $i++){}
  56.   $time['end'] = microtime(true);
  57.   $leerlaufres[] = $time['end']-$time['start'];
  58. }
  59. $leerlaufres = array_sum($leerlaufres)/$quant/2;
  60.  
  61.  
  62. $average[1] = (array_sum($results[1])/($quant-1)-$leerlaufres)*1000; // ms 1 func
  63. $average[2] = (array_sum($results[2])/($quant-1)-$leerlaufres)*1000; // ms 2 func
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement