1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
15
|
|
|
* |
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
17
|
|
|
* and is licensed under the LGPL. For more information please see |
18
|
|
|
* <http://phing.info>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Phing\Util; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Siad Ardroumli <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class DefaultClock implements Clock |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* start time. |
30
|
|
|
* |
31
|
|
|
* @var float |
32
|
|
|
*/ |
33
|
|
|
protected $stime; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* end time. |
37
|
|
|
* |
38
|
|
|
* @var float |
39
|
|
|
*/ |
40
|
|
|
protected $etime; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* is the timer running. |
44
|
|
|
* |
45
|
|
|
* @var bool |
46
|
|
|
*/ |
47
|
|
|
protected $running; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Starts the timer and sets the class variable $stime to the current time in microseconds. |
51
|
|
|
*/ |
52
|
|
|
public function start() |
53
|
|
|
{ |
54
|
|
|
$this->stime = $this->getCurrentTime(); |
55
|
|
|
$this->running = true; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Stops the timer and sets the class variable $etime to the current time in microseconds. |
60
|
|
|
*/ |
61
|
|
|
public function stop() |
62
|
|
|
{ |
63
|
|
|
$this->etime = $this->getCurrentTime(); |
64
|
|
|
$this->running = false; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* This function returns the elapsed time in seconds. |
69
|
|
|
* |
70
|
|
|
* Call start_time() at the beginning of script execution and end_time() at |
71
|
|
|
* the end of script execution. Then, call elapsed_time() to obtain the |
72
|
|
|
* difference between start_time() and end_time(). |
73
|
|
|
* |
74
|
|
|
* @param int $places decimal place precision of elapsed time (default is 5) |
75
|
|
|
* |
76
|
|
|
* @return string properly formatted time |
77
|
|
|
*/ |
78
|
|
|
public function getElapsedTime($places = 5) |
79
|
|
|
{ |
80
|
|
|
$etime = $this->etime - $this->stime; |
81
|
|
|
$format = '%0.' . $places . 'f'; |
82
|
|
|
|
83
|
|
|
return sprintf($format, $etime); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
|
public function isRunning() |
90
|
|
|
{ |
91
|
|
|
return $this->running; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return int |
96
|
|
|
*/ |
97
|
|
|
public function getCurrentTime() |
98
|
|
|
{ |
99
|
|
|
return microtime(true); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|