StopWatch

StopWatch

class StopWatch {

    private static $startTimes = array();

    public static function start($timerName = 'default') {
        self::$startTimes[$timerName] = microtime(true);
    }

    public static function elapsed($timerName = 'default') {
        return microtime(true) - self::$startTimes[$timerName];
    }

}

 Exemple d’utilisation : 

StopWatch::start();
sleep(5); // perform long running operation
echo sprintf("Operation completed in %s seconds", StopWatch::elapsed());

 

Partager

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *