Overview

Packages

  • Support

Classes

  • Horde_Support_Array
  • Horde_Support_Backtrace
  • Horde_Support_CombineStream
  • Horde_Support_ConsistentHash
  • Horde_Support_Guid
  • Horde_Support_Inflector
  • Horde_Support_Memory
  • Horde_Support_Numerizer
  • Horde_Support_Numerizer_Locale_Base
  • Horde_Support_Numerizer_Locale_De
  • Horde_Support_Numerizer_Locale_Pt
  • Horde_Support_Randomid
  • Horde_Support_Stack
  • Horde_Support_StringStream
  • Horde_Support_Stub
  • Horde_Support_Timer
  • Horde_Support_Uuid
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Simple interface for timing operations.
 4:  *
 5:  * <code>
 6:  *  $t = new Horde_Support_Timer;
 7:  *  $t->push();
 8:  *  $elapsed = $t->pop();
 9:  * </code>
10:  *
11:  * Copyright 1999-2012 Horde LLC (http://www.horde.org/)
12:  *
13:  * @category   Horde
14:  * @package    Support
15:  * @license    http://www.horde.org/licenses/bsd
16:  */
17: class Horde_Support_Timer
18: {
19:     /**
20:      * Holds the starting timestamp.
21:      *
22:      * @var array
23:      */
24:     protected $_start = array();
25: 
26:     /**
27:      * Current index for stacked timers.
28:      *
29:      * @var integer
30:      */
31:     protected $_idx = 0;
32: 
33:     /**
34:      * Push a new timer start on the stack.
35:      */
36:     public function push()
37:     {
38:         $start = $this->_start[$this->_idx++] = microtime(true);
39:         return $start;
40:     }
41: 
42:     /**
43:      * Pop the latest timer start and return the difference with the current
44:      * time.
45:      *
46:      * @return float The amount of time passed.
47:      */
48:     public function pop()
49:     {
50:         $etime = microtime(true);
51: 
52:         if (! ($this->_idx > 0)) {
53:             throw new Exception('No timers have been started');
54:         }
55: 
56:         return $etime - $this->_start[--$this->_idx];
57:     }
58: 
59: }
60: 
API documentation generated by ApiGen