-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTicks.php
66 lines (60 loc) · 1.54 KB
/
Ticks.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
Ticks measurement.
*/
class cTicks
{
private $dtStart; //!< Start time set upon creation of this class
private $dtEnd; //!< End time set upon calling pf_getDurations
private $arrTicks; //!< Ticks array
public function __construct()
{
$this->dtStart = $this->pf_getTickStamp();
}
/**
* Function gets tick stamp (microtime).
*
* @return float Time in seconds since Unix epoch with microseconds after coma.
*/
private function pf_getTickStamp()
{
$mtime = microtime(); // e.g. 0.65504100 1361641864
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
return $mtime;
}
/**
* Insert a named tick
*
* @warning Always call insert and end tick in pairs!
*/
public function pf_insTick($strTickName, $endPrevious = false)
{
if ($endPrevious && !empty($this->startedTickName)) {
$this->pf_endTick($this->startedTickName);
}
$this->arrTicks[$strTickName] = $this->pf_getTickStamp();
$this->startedTickName = $strTickName;
}
/** End a named tick (calculate duration) */
public function pf_endTick($strTickName)
{
if (isset($this->arrTicks[$strTickName]))
{
$this->arrTicks[$strTickName] = $this->pf_getTickStamp() - $this->arrTicks[$strTickName];
}
}
/**
* Get durations array.
*
* @param boolean $boolAddTotal
* @return array
*/
public function pf_getDurations($boolAddTotal=true)
{
$this->dtEnd = $this->pf_getTickStamp();
$this->arrTicks['total'] = $this->dtEnd - $this->dtStart;
return $this->arrTicks;
}
}
?>