Monday, November 09, 2009

PHP Script Execution Stopwatch

This is more a note to self...
To measure the time between two points in a PHP script, this works in a simple and effective way:

$x = explode(' ', microtime());
$start = $x[1].substr($x[0], 1);
print_r(apache_get_modules());
$x = explode(' ', microtime());
$stop = $x[1].substr($x[0], 1);

$bench = bcsub($stop, $start, 6);
print "Time: " . number_format($bench, 3);


I just measured the time taken for apache_get_modules() to run and print_r, which isn't much. I suppose number_format() can be omitted to avoid panic on shorter runtimes.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.