A little modification to the Timer class by ed [at]
twixcoding [dot] com. With this class you can pause and
unpause the timer and selectively exclude certain areas of
your code from the total time.
<?php
class Timer {
var $s;
var $p = 0;
function start() {
$this->s = $this->getmicrotime();
}
function pause() {
$this->p = $this->getmicrotime();
}
function unpause() {
$this->s += ($this->getmicrotime() - $this->p);
$this->p = 0;
}
function fetch($decimalPlaces = 3) {
return round(($this->getmicrotime() - $this->s),
$decimalPlaces);
}
function getmicrotime() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
}
// ------------------- TEST ----------------------------
$t = new Timer();
$t->start();
sleep(1);
var_dump($t->fetch()); // Outputs: float(0.999)
$t->start();
$t->pause();
sleep(1);
$t->unpause();
var_dump($t->fetch()); // Outputs: float(0)
// ------------------------------------------------------
?>
----
Server IP: 85.111.4.6
Probable Submitter: 85.99.113.121
----
X-Spam-Status: No, hits=3.1 required=5.0
tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- h
ttp://www.php.net/manual/en/function.microtime.php
Edit -- http://master.p
hp.net/note/edit/66877
Del: integrated -- ht
tp://master.php.net/note/delete/66877/integrated
Del: useless -- http:
//master.php.net/note/delete/66877/useless
Del: bad code -- http
://master.php.net/note/delete/66877/bad+code
Del: spam -- http://m
aster.php.net/note/delete/66877/spam
Del: non-english -- h
ttp://master.php.net/note/delete/66877/non-english
Del: in docs -- http:
//master.php.net/note/delete/66877/in+docs
Del: other reasons-- http://master
.php.net/note/delete/66877
Reject -- http://master
.php.net/note/reject/66877
Search -- http://ma
ster.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|