Jun 15, 2009

Optimization: How to time your scripts

When looking for bottle-necks in your application, you sometimes need to check how long a certain code segment runs.
Here is how to measure it:


list($usec, $sec) = explode(" ", microtime());$t1=((float)$usec + (float)$sec);
// the CODE SEGMENT goes here
list($usec, $sec) = explode(" ", microtime());$t2=((float)$usec + (float)$sec);
$time = (float)($t2-$t1);
echo $time;

No comments:

Post a Comment