Archives de
Catégorie : PHP

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());