<?php
class profiler {
private $count = 0;
private $time = array();
public function __construct() {
return $this->start();
}
public function start() {
$r = false;
if (!isset($this->time[0])) {
$this->add("start", microtime(true));
$r = true;
}
return $r;
}
public function lap($id = "lap") {
$r = false;
if (isset($this->time[0])) {
$rest = $this->count == 1 ? $this->time[0]['dur'] : $this->time[0]['dur'] + $this->time[$this->count-1]['dur'];
$this->add($id, microtime(true) - $rest);
if ($id == "end") {
array_shift($this->time);
$r = $this->time;
$this->__destruct();
}
else $r = true;
}
return $r;
}
private function add($id, $time) {
$this->time[] = array("id" => $id, "dur" => $time);
$this->count++;
}
public function stop() {
return $this->lap("end");
}
public function __destruct() {
$this->count = 0;
$this->time = array();
}
}
?>
|