note 57230 deleted from function.microtime by tularis
| From: | tularis@php.net | Date: | Sun, 22 Jun 2008 12:14:00 +0000 |
| Subject: | note 57230 deleted from function.microtime by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-140698@lists.php.net to get a copy of this message | ||
Note Submitter: martijn at vanderlee dot com
----
For highly accurate performance timing of an algorithm, you'll need to take into account the
time it takes to run microtime() and/or a replacement function such as the microtime_float.
Make sure to keep all calculations outside the timers.
Here's a small sample. Please note that it takes into account the assignment of one variable as
well during calibration, since this will happen in the actual test as well.
$calibrate_begin = microtime_float();
$calibrate_end = microtime_float();
$overhead_time = $calibrate_end - $calibrate_begin;
$performance_begin = microtime_float();
// test
$performance_end = microtime_float();
$result_time = ($performance_end - $performance_begin) - $overhead_time;
For even more accuracy in testing, loop the ENTIRE code a number of times. If you just loop the
calibration and test independantly, you'll get misleading results due to time spent running the
loop codes themselves.