started = false; if ($start) $this->start(); } function start() { $startMtime = explode(' ',microtime()); $this->startTime = (double)($startMtime[0])+(double)($startMtime[1]); $this->started = true; } function end($iterations=1) { // get the time, check whether the timer was started later $endMtime = explode(' ',microtime()); if ($this->started) { $endTime = (double)($endMtime[0])+(double)($endMtime[1]); $dur = $endTime - $this->startTime; $avg = 1000*$dur/$iterations; $avg = round(1000*$avg)/1000; return "$avg milliseconds"; } else { return "timer not started"; } } } ?>