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
|
<?php /** * Class StopWatchEvent. * * @package AmpProject\AmpWP */
namespace AmpProject\AmpWP\Instrumentation;
/** * Record the timing of a single event. * * @package AmpProject\AmpWP * @since 2.0 * @internal */ final class StopWatchEvent {
/** * Start time in milliseconds. * * @var float */ private $start;
/** * End time in milliseconds. * * @var float|null */ private $end;
/** * StopWatchEvent constructor. */ public function __construct() { $this->start = $this->get_now(); }
/** * Stop the event. */ public function stop() { $this->end = $this->get_now(); }
/** * Get the duration of the event in milliseconds. * * @return float Duration in milliseconds. */ public function get_duration() { if ( null === $this->end ) { return 0.0; }
return $this->end - $this->start; }
/** * Get the current time in milliseconds. * * @return float Current time in milliseconds. */ private function get_now() { return microtime( true ) * 1000; } }
|