PluginProbe
Datafeedr API / 1.2.3
Datafeedr API v1.2.3
1.4.2 1.0.125 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 All 181 releases
datafeedr-api / classes / class-datafeedr-timer.php

class-datafeedr-timer.php in Datafeedr API 1.2.3, at classes/class-datafeedr-timer.php

79 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 * Trait Datafeedr_Timer
5 *
6 * Imports timer functionality into any class.
7 *
8 * @since 1.0.72
9 */
10 trait Datafeedr_Timer {
11
12 /**
13 * If used and set to TRUE, microtime() will return a float instead
14 * of a string, as described in the return values section below.
15 *
16 * @since 1.0.72
17 * @access public
18 * @var bool $microtime_as_float
19 */
20 public $microtime_as_float = true;
21
22 /**
23 * Start time.
24 *
25 * @since 1.0.72
26 * @access protected
27 * @var float $time_start
28 */
29 protected $time_start = 0;
30
31 /**
32 * Stop time.
33 *
34 * @since 1.0.72
35 * @access protected
36 * @var float $time_stop
37 */
38 protected $time_stop = 0;
39
40 /**
41 * Starts the timer.
42 *
43 * @since 1.0.72
44 */
45 public function start_timer() {
46 $this->time_start = microtime( $this->microtime_as_float );
47 }
48
49 /**
50 * Stops the timer.
51 *
52 * @since 1.0.72
53 */
54 public function stop_timer() {
55 $this->time_stop = microtime( $this->microtime_as_float );
56 }
57
58 /**
59 * Return rounded elapsed time.
60 *
61 * @param int $precision Optional. How much to round float value. Default 2.
62 *
63 * @return float
64 */
65 public function execution_time( $precision = 2 ) {
66 $time = $this->elapsed_time();
67
68 return round( $time, $precision );
69 }
70
71 /**
72 * Return elapsed time.
73 *
74 * @return float
75 */
76 public function elapsed_time() {
77 return ( $this->time_stop - $this->time_start );
78 }
79 }