note 66877 added to function.microtime

From: Date: Wed, 31 May 2006 10:51:07 +0000
Subject: note 66877 added to function.microtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-112629@lists.php.net to get a copy of this message
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 -- http://www.php.net/manual/en/function.microtime.php Edit -- http://master.php.net/note/edit/66877 Del: integrated -- http://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://master.php.net/note/delete/66877/spam Del: non-english -- http://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://master.php.net/manage/user-notes.php

« previous php.notes (#112629) next »