Added templates
[bibliodb.git] / profiller.php
blob34cafb39067be571083ee5d09accec216810b415
1 <?php
2 class Profiller{
3 //enforce singleton
4 protected $time_log=array();
5 protected $last_time=0;
6 final private function __clone() {}
7 final private function __construct() {
10 final private static function getInstance()
12 static $instance = null;
14 if (null === $instance) {
15 $instance = new self();
17 return $instance;
19 public function show(){
20 $inst=self::getInstance();
21 echo "<table>\n<tr><th>Message</th><th>Time</th></tr>\n";
22 foreach($inst->time_log as $log){
23 echo "<tr><td>{$log[message]}</td><td>{$log[time]}</td></tr>\n";
25 echo "</table>\n";
27 public function speed($message){
28 $curr_time=microtime();
29 $inst=self::getInstance();
30 $last_time=($inst->last_time>0)?$inst->last_time:$curr_time;
31 $ellapsed=$curr_time-$last_time;
32 $inst->time_log[]=array("time"=>$ellapsed,"message"=>$message);
33 $inst->last_time=microtime();