Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $quant = 15;
- $repeat = 10000;
- $results[1] = array(); // results of first function
- $results[2] = array(); // results of second function
- $b = null;
- # Durchlauf
- for($c=1; $c<=$quant*2; $c++){
- $time['start'] = microtime(true);
- if($c%2) // 1,3,5,...
- for($i=0; $i<$repeat; $i++){
- # first Function
- is_null($b);
- is_null($b);
- is_null($b);
- is_null($b);
- is_null($b);
- is_null($b);
- is_null($b);
- is_null($b);
- is_null($b);
- is_null($b);
- is_null($b);
- is_null($b);
- }
- else // 2,4,6,...
- for($i=0; $i<$repeat; $i++){
- # second Function
- $b===NULL;
- $b===NULL;
- $b===NULL;
- $b===NULL;
- $b===NULL;
- $b===NULL;
- $b===NULL;
- $b===NULL;
- $b===NULL;
- $b===NULL;
- $b===NULL;
- $b===NULL;
- }
- $time['end'] = microtime(true);
- $results[!($c%2)+1][] = $time['end']-$time['start'];
- }
- $leerlaufres = array(); // results of empty for()-loop
- for($c=1; $c<=$quant*2; $c++){ # Leerlauf messen
- $time['start'] = microtime(true);
- if($c%2) // 1,3,5,...
- for($i=0; $i<$repeat; $i++){}
- else // 2,4,6,...
- for($i=0; $i<$repeat; $i++){}
- $time['end'] = microtime(true);
- $leerlaufres[] = $time['end']-$time['start'];
- }
- $leerlaufres = array_sum($leerlaufres)/$quant/2;
- $average[1] = (array_sum($results[1])/($quant-1)-$leerlaufres)*1000; // ms 1 func
- $average[2] = (array_sum($results[2])/($quant-1)-$leerlaufres)*1000; // ms 2 func
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement