forked from glympero/php-execution-time-recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExecutionTimeRecorder.php
110 lines (94 loc) · 2.67 KB
/
ExecutionTimeRecorder.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
class ExecutionTimeRecorder {
//The name of the timer
private $name = "Timer";
//Start time of a timer
private $time_start = 0.0;
//End time of a timer
private $time_end = 0.0;
//Execution time of a timer
private $time = 0.0;
//Execution time of all timers
static $total_exec = 0.0;
//Number of timers used
static $number_timers = 0; //Number of timers used
/**
* Returns the name of a timer
* @return String
*/
public function getName() {
return $this->name;
}
/**
* Returns the start time of a timer
* @return String
*/
public function getTimeStart() {
return $this->time_start;
}
/**
* Returns the end time of a timer
* @return String
*/
public function getTimeEnd() {
return $this->time_end;
}
/**
* Return the execution time of a timer
* @return Float
*/
public function getTime() {
return $this->time;
}
/**
* Return the execution time of all timers
* @return Float
*/
static function getTotalExec() {
return static::$total_exec;
}
/**
* Return the execution time of all timers
* @return Float
*/
static function getNumberTimers() {
return static::$number_timers;
}
/**
* Returns the name and execution time of the timer
* @return String
*/
public function totalTimer() {
return "It took " . $this->getTime() . " seconds to run " . $this->getName() . " <br>";
}
/**
* Function to start a timer. Increments number of timers used
* @param String $name
* @return void
*/
public function startTimer($name = null) {
//Name Provided?
if ($name != "" && $name != null) {
$this->name = $name;
}
$this->time_start = microtime(true);
static::$number_timers++;
}
/**
* Function to end a timer. Increments the execution time of all timers
* return void
*/
public function endTimer() {
$this->time_end = microtime(true);
$this->time = number_format(($this->time_end - $this->time_start), 5);
static::$total_exec += $this->time;
}
/**
* Return description with number of timers used and time to run the entire page
* @return String
*/
static function totalExecution() {
return static::getNumberTimers() . " Timers have been used and it "
. "took " . static::getTotalExec() . " seconds to run them.<br/> It also took " . number_format((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), 5) . " seconds to run the entire page";;
}
}