PluginProbe
Datafeedr API / 1.4.3
Datafeedr API v1.4.3
1.4.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 All 182 releases
datafeedr-api / classes / class-datafeedr-timer.php

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

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