note 66877 deleted from function.microtime by tularis

From: Date: Sun, 22 Jun 2008 12:08:58 +0000
Subject: note 66877 deleted from function.microtime by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140681@lists.php.net to get a copy of this message
Note Submitter: emre [[at]] olmayan.org ---- 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) // ------------------------------------------------------ ?>

« previous php.notes (#140681) next »