/
Benchmark.php
38 lines (33 loc) · 894 Bytes
/
Benchmark.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace mcanan\framework;
class Benchmark
{
private $timestamps = array();
public function reset()
{
$this->timestamps = array();
}
public function mark($name)
{
$this->timestamps[]= array($name,microtime(true));
}
public function getTimestampsAsHtmlComment()
{
$total = $this->timestamps[count($this->timestamps)-1][1]-$this->timestamps[0][1];
$html="\n<!--\n";
$last = -1;
foreach ($this->timestamps as $t) {
if ($last>0) {
$val = round($t[1] - $last, 3);
$prc = round(($val/$total)*100);
$html.="$t[0] - $val - $prc%\n";
} else {
$html.="$t[0] - 0\n";
}
$last = $t[1];
}
$html.="Total - ".round($total, 3)."\n";
$html.="-->\n";
return $html;
}
}