note 71199 deleted from function.microtime by tularis

From: Date: Sun, 22 Jun 2008 12:07:57 +0000
Subject: note 71199 deleted from function.microtime by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140675@lists.php.net to get a copy of this message
Note Submitter: lacent at gmail dot com ---- i've made several timer functions, and different methods of how to check time, for loading and benchmarking and such. this class works pretty good for whatever you might need it for. start it, then use stopwatch::now() to check time at that moment. it doesn't affect the start time so you can check the loadtime at that moment several times within your script, or run multiple stopwatches. <?php class stopwatch { private $round = 3; function __construct ( ) { $this->start = microtime(); } function now ( ) { $start = $this->math($this->start); $now = $this->math(); return round($now - $start, $this->round); } function math ($time = FALSE) { if ( !$time ) $time = microtime(); $temp = explode(' ', $time); return $temp[0] + $temp[1]; } } ?> usage: $stopwatch = new stopwatch(); /* some code */ echo $stopwatch->now();

« previous php.notes (#140675) next »