note 71199 added to function.microtime

From: Date: Thu, 16 Nov 2006 02:19:16 +0000
Subject: note 71199 added to function.microtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-119765@lists.php.net to get a copy of this message
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(); ---- Server IP: 216.194.113.175 Probable Submitter: 216.136.83.245 ---- Manual Page -- http://www.php.net/manual/en/function.microtime.php Edit -- https://master.php.net/note/edit/71199 Del: integrated -- https://master.php.net/note/delete/71199/integrated Del: useless -- https://master.php.net/note/delete/71199/useless Del: bad code -- https://master.php.net/note/delete/71199/bad+code Del: spam -- https://master.php.net/note/delete/71199/spam Del: non-english -- https://master.php.net/note/delete/71199/non-english Del: in docs -- https://master.php.net/note/delete/71199/in+docs Del: other reasons-- https://master.php.net/note/delete/71199 Reject -- https://master.php.net/note/reject/71199 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119765) next »