PHP Code Execution Timing Script

Place call to startTimer() at beginning where timing is to start. At end of script to time call stopTimer() and this will calculate and return elapsed time of execution in seconds to seven decimal places.


function startTimer() {
  define('START_TIME',microtime(true));

}

function stopTimer() {
    $total = microtime(TRUE) - START_TIME;
    return '<Br>'.sprintf('Executed in %.7f seconds.', $total);
}

//Usage

startTimer();

//the code to time.....
sleep(5);

echo stopTimer();


Leave a comment

5 Comments.

  1. Thanks $author! Amazing page! It’s just like an activity on behalf of me. It’s therefore useful also usefull, thanks a lot! When you article more of this cool php scripts, I’ll explore your site again.

    • yes,not sure if i should post code here but while ($row = mysql_fetch_assoc($res)){ $sql= scelet count(*) as num_replies from `forum_replies` where `tid`=’ .$row['id']. ;is what looks like the important part that could be screwing it up.

    • thx for your tutorial!!! I leaenrd alot! has the series of PHP Forum tutorial finished? or few more lessons? I watched all the tutorial in your websites!Thanks for your sharing and time!!! WE really appreciate it!

    • whew.. this shows that Filipinos still don’t forget the One who gives us kwgoledne and strength That 3day fasting might be perceived as a pain, but the one with true convictions will not see it as a problem, but as a sincere prayer..God bless you and our beloved country -

  2. it’so nice page as well as usefull for those who want to php code,

    can u post more script of php.

    thanks