|
From: Rene R. <re...@gr...> - 2002-09-17 09:03:08
|
Hi Joe.
I've begun testing the performance of the database to see where it could
use some optimization.
These two functions make it easy.
Add a "var $time; to the class you want to test and the functions below.
It'll handle several names in one turn and add timings to display a
total. (good for loops inside loops)
I use it like this:
// start the timer
$this->timer("Array_merge", microtime(), "start");
// whatever you measure gets done here.
$result = array_merge($result, $this->compare_data ($db_data, $array));
//stop the timer
$this->timer("Array_merge", microtime(), "stop");
// print the result
$this->get_times();
-------- functions ------ beware of line-wraps -------
// just a simple performance counter
function timer ( $name, $microtime , $type) {
list($usec, $sec) = explode(" ",$microtime);
$time = ((float)$usec + (float)$sec);
if ( $type == "start" ) {
$this->time["start"][$name] = $time;
} else {
$this->time["stop"][$name] = $time;
// add the difference to total
$this->time["total"][$name] = ($this->time["stop"][$name] -
$this->time["start"][$name]) +$this->time["total"][$name];
}
return;
}
function get_times () {
$names = array_keys($this->time["total"]);
foreach ( $names as $name ) {
echo "Total time for $name was : " . $this->time["total"][$name] . "
seconds<br>";
}
return;
}
|