rendered paste body<?php
class Profiler {
private $events = Array();
function __construct() {
$this->start("total", "Total time");
}
function start($id, $name) {
$this->events["$id"] = Array(
"name" => $name,
"start" => microtime(true),
"stop" => 0,
"total" => 0
);
}
function stop($id) {
if (isset($this->events[$id]) and $this->events[$id]["total"] == 0) {
$this->events[$id]["stop"] = microtime(true);
$this->events[$id]["total"] = $this->events[$id]["stop"] - $this->events[$id]["start"];
}
}
function report() {
foreach($this->events as $id => $event) {
$this->stop($id);
}
return $this->events;
}
}
$count = 0;
$profiler = new Profiler;
$profiler->start("counter", "Count from 0 to 10000");
// Waste some time...
while($count++ < 10000000);
$profiler->stop("counter");
// Waste some more time...
while($count++ < 20000000);
var_dump($profiler->report());
?>