ref::timer PHP Method

timer() public static method

First call of this function will start the timer. The second call will stop the timer and return the elapsed time since the timer started. Multiple timers can be controlled simultaneously by specifying a timer ID.
Since: 1.0
public static timer ( integer $id = 1, integer $precision = 4 ) : void | double
$id integer Timer ID, optional
$precision integer Precision of the result, optional
return void | double Elapsed time, or void if the timer was just started
    public static function timer($id = 1, $precision = 4)
    {
        static $timers = array();
        // check if this timer was started, and display the elapsed time if so
        if (isset($timers[$id])) {
            $elapsed = round(microtime(true) - $timers[$id], $precision);
            unset($timers[$id]);
            return $elapsed;
        }
        // ID doesn't exist, start new timer
        $timers[$id] = microtime(true);
    }