DomingoSL DomingoSL - 1 year ago 59
PHP Question

Accurate way to measure execution times of php scripts

I want to know how many milliseconds a PHP for-loop takes to execute.

I know the structure of a generic algorithm, but no idea how to implement it in PHP:

init1 = timer(); // where timer() is the amount of milliseconds from midnight
the loop begin
some code
the loop end
total = timer() - init1;

Answer Source

You can use the microtime function for this. From the documentation:

microtime — Return current Unix timestamp with microseconds

Example usage:

$start = microtime(true);
while (...) {

$time_elapsed_secs = microtime(true) - $start;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download