$execution_time = microtime(); // Start counting
// Your code
$execution_time = microtime() - $execution_time;
printf('It took %.5f sec', $execution_time);
Count Script Excecution Time
Chris Coyier
on
or
to display the output.
I would suggest something like this…
Here’s the stripped down version of daGrevis’ fine work:
Howdy,
Just wanted to say thanks for this article, I used it to test the difference between a single MySQL call and a file being picked up locally. The difference was amazing Local file storage was 6-7 faster!!!!
Matt
Since php 5.1, the timestamp of the start of the request is available in
$_SERVER['REQUEST_TIME']
So you can do :
Perhaps
register_shutdown_function()
could be of some use here :)I time all my programs and log the timing to a file to help me tune my database system. I have developed a class to help.
in my programs, after I make sure the class is loaded (I depend on
__autoload
) All I need is one line.As part of php cleanup, the destructor will run and print out the timing. I have the instantiation statement in a
require_once
file.In the example above it just prints the result. My actual destructor writes to a log file so I can average timings.