~ubuntu-branches/ubuntu/saucy/horde3/saucy

« back to all changes in this revision

Viewing changes to lib/Horde/Timer.php

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2005-05-04 23:08:08 UTC
  • Revision ID: james.westby@ubuntu.com-20050504230808-p4hf3hk28o3v7wir
Tags: upstream-3.0.4
ImportĀ upstreamĀ versionĀ 3.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Simple interface for timing operations/actions.
 
4
 *
 
5
 * $Horde: framework/Timer/Timer.php,v 1.6 2004/08/30 13:38:18 chuck Exp $
 
6
 *
 
7
 * @package Horde_Timer
 
8
 * @since   Horde 3.0
 
9
 */
 
10
class Horde_Timer {
 
11
 
 
12
    /**
 
13
     * @var array $_start
 
14
     */
 
15
    var $_start = array();
 
16
 
 
17
    /**
 
18
     * @var integer $idx
 
19
     */
 
20
    var $_idx = 0;
 
21
 
 
22
    /**
 
23
     * Push a new timer start on stack.
 
24
     */
 
25
    function push()
 
26
    {
 
27
        list($ms, $s) = explode(' ', microtime());
 
28
        $this->_start[$this->_idx++] = floor($ms * 1000) + 1000 * $s;
 
29
    }
 
30
 
 
31
    /**
 
32
     * Pop the latest timer start and return the difference with the
 
33
     * current time.
 
34
     */
 
35
    function pop()
 
36
    {
 
37
        assert($this->_idx > 0);
 
38
        list($ms, $s) = explode(' ', microtime());
 
39
        $etime = floor($ms * 1000) + (1000 * $s);
 
40
        $this->_idx--;
 
41
        return $etime - $this->_start[$this->_idx];
 
42
    }
 
43
 
 
44
    /**
 
45
     * Return a reference to a global Horde_Timer engine.
 
46
     */
 
47
    function &singleton()
 
48
    {
 
49
        static $timer;
 
50
 
 
51
        if (!isset($timer)) {
 
52
            $timer = new Horde_Timer();
 
53
        }
 
54
 
 
55
        return $timer;
 
56
    }
 
57
 
 
58
}