File: //usr/local/mailchannels/lib/TimeProfiler.php
<?php
class TimeProfiler {
public static $times = array();
public static $counts = array();
public static function profileTime($label, $func) {
$time_pre = microtime(true);
$func();
$time = microtime(true) - $time_pre;
if (array_key_exists($label, self::$times)) {
self::$times[$label] += $time;
self::$counts[$label]++;
} else {
self::$times[$label] = $time;
self::$counts[$label] = 1;
}
return $time;
}
public static function echoTimes() {
foreach (self::$times as $label=>$time) {
$counted = self::$counts[$label];
echo "TIME_PROFILE for $label: total time: $time; times counted: $counted\n";
}
}
}