PluginProbe
404 Solution / 4.1.13
404 Solution v4.1.13
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / Timer.php

Timer.php in 404 Solution 4.1.13, at includes/Timer.php

67 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 if (!defined('ABSPATH')) {
5 exit;
6 }
7
8 class ABJ_404_Solution_Timer {
9
10 /** @var float */
11 private $start = 0;
12
13 /** @var float */
14 private $stop = 0;
15
16 /** @var float */
17 private $elapsed = 0;
18
19 /** @var bool */
20 private $isRunning = false;
21
22 public function __construct() {
23 $this->start();
24 }
25
26 /** Also restart.
27 * @return void
28 */
29 function start(): void {
30 $this->start = microtime(true);
31 $this->elapsed = 0;
32 $this->isRunning = true;
33 }
34
35 /** @return float */
36 function stop(): float {
37 $this->stop = microtime(true);
38 $elapsedThisTime = $this->stop - $this->start;
39 $this->elapsed += $elapsedThisTime;
40 $this->isRunning = false;
41
42 return $this->getElapsedTime();
43 }
44
45 /** @return void */
46 function restartKeepElapsed(): void {
47 $this->start = microtime(true);
48 $this->isRunning = true;
49 }
50
51 /**
52 * @return float in seconds
53 */
54 function getElapsedTime() {
55 if ($this->isRunning) {
56 return microtime(true) - $this->start + $this->elapsed;
57 }
58 return $this->elapsed;
59 }
60
61 /** @return float */
62 function getStartTime(): float {
63 return $this->start;
64 }
65
66 }
67