I'd like to do this on my site too so that I can see how fast my MySQL queries are executing and how fast the php page is loading:!: However I have not come across any tutorials on it. Could someone point me in the right direction?
TIA.
Moderator: General Moderators
Code: Select all
class c_Timer {
var $t_start = 0;
var $t_stop = 0;
var $t_elapsed = 0;
function start() { $this->t_start = microtime(); }
function stop() { $this->t_stop = microtime(); }
function elapsed() {
if ($this->t_elapsed) {
return $this->t_elapsed;
} else {
$start_u = substr($this->t_start,0,10); $start_s = substr($this->t_start,11,10);
$stop_u = substr($this->t_stop,0,10); $stop_s = substr($this->t_stop,11,10);
$start_total = doubleval($start_u) + $start_s;
$stop_total = doubleval($stop_u) + $stop_s;
$this->t_elapsed = $stop_total - $start_total;
print "<b>Benchmark: $this->t_elapsed seconds</b>";
return $this->t_elapsed;
}
}
}Code: Select all
<class function here>
$BenchmarkTimer = new c_Timer;
$BenchmarkTimer->start();
<your program here>
$BenchmarkTimer->stop();
$BenchmarkTimer->elapsed();