Elapsed microtime counter

Counts the elapsed seconds when doing some process.

Snippet information

Author:
Jonas John

License:
Public Domain

Language:
PHP

Created:
05/26/2006

Updated:
05/26/2006

Tags:
,


// mt_get: returns the current microtime
function mt_get(){
    global $mt_time;
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}
 
// mt_start: starts the microtime counter
function mt_start(){
    global $mt_time; $mt_time = mt_get();
}
 
// mt_end: calculates the elapsed time
function mt_end($len=4){
    global $mt_time;
    $time_end = mt_get();
    return round($time_end - $mt_time, $len);
}


Found a bug? Or do you have a better solution for this?
Feel free to leave a message:

Add a comment


Leave a comment