version 1.2, 2002/08/16 21:54:38 |
version 1.3, 2002/09/25 18:06:20 |
|
|
<?php
|
<?php |
/*
|
/* |
This is a generic timer class.
|
This is a generic timer class. |
|
|
version 0.1 - 18-Jun-01
|
version 0.1 - 18-Jun-01 |
|
|
Written by Jim Kraai (JimKraai@Polytopic.com)
|
Written by Jim Kraai (JimKraai@Polytopic.com) |
|
|
$Id$
|
$Id$ |
*/
|
*/ |
|
|
class timerClass {
|
class timerClass |
|
{ |
var $startTime;
|
var $startTime; |
var $started;
|
var $started; |
|
|
function timerClass($start=true) {
|
function timerClass($start=true) { |
$this->started = false;
|
$this->started = false; |
if ($start)
|
if ($start) |
$this->start();
|
$this->start(); |
}
|
} |
|
|
function start() {
|
function start() { |
$startMtime = explode(' ',microtime());
|
$startMtime = explode(' ',microtime()); |
$this->startTime = (double)($startMtime[0])+(double)($startMtime[1]);
|
$this->startTime = (double)($startMtime[0])+(double)($startMtime[1]); |
$this->started = true;
|
$this->started = true; |
}
|
} |
|
|
function end($iterations=1) {
|
function end($iterations=1) { |
// get the time, check whether the timer was started later
|
// get the time, check whether the timer was started later |
$endMtime = explode(' ',microtime());
|
$endMtime = explode(' ',microtime()); |
if ($this->started) {
|
if ($this->started) { |
$endTime = (double)($endMtime[0])+(double)($endMtime[1]);
|
$endTime = (double)($endMtime[0])+(double)($endMtime[1]); |
$dur = $endTime - $this->startTime;
|
$dur = $endTime - $this->startTime; |
$avg = 1000*$dur/$iterations;
|
$avg = 1000*$dur/$iterations; |
$avg = round(1000*$avg)/1000;
|
$avg = round(1000*$avg)/1000; |
return "$avg milliseconds";
|
return "$avg milliseconds"; |
} else {
|
} else { |
return "timer not started";
|
return "timer not started"; |
}
|
} |
}
|
} |
|
|
}
|
} |
?>
|
|
|
?> |