Login  or  Register  / Search

Using PHP High Precision Timer

On PHP5.4 there a new function that we can use to check our code performance and using new PHP high precision timer would help us to benchmark our apps.

So we go test it and let’s get started.

create a new PHP file and let’s call it “elapse-time.php”

<?php

    $less_time = $_SERVER["REQUEST_TIME_FLOAT"];

    echo "Elapsed Time : ", microtime(true) - $less_time ," seconds <br />";

?>

What’s microtime?
microtime return current unix timestamp with microseconds.

So meaning to test out your PHP script you need to put the elapse-time.php below your code.

elapse-time.php

<?php

    $less_time = $_SERVER["REQUEST_TIME_FLOAT"];

    // your code start here
 
    // your code ends here

    echo "Elapsed Time : ", microtime(true) - $less_time ," seconds <br />";

?>

So with this simple code you can see how long does it take your script execute and may check for any bottlenecks.