source: trunk/lib/ScriptTimer.inc.php @ 1

Last change on this file since 1 was 1, checked in by scdev, 19 years ago

Initial import.

File size: 1.1 KB
Line 
1<?php
2/**
3 * ScriptTimer.inc.php
4 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
5 */
6 
7class ScriptTimer {
8
9    var $time_format = '%.10f';
10    var $_timing_start_times;
11    var $_timing_stop_times;
12   
13    function start($name='default')
14    {
15        $this->_timing_start_times[$name] = explode(' ', microtime());
16    }
17   
18    function stop($name='default')
19    {
20        $this->_timing_stop_times[$name] = explode(' ', microtime());
21    }
22   
23    function getTime($name='default')
24    {
25        if (!isset($this->_timing_start_times[$name])) {
26            return 0;
27        }
28       
29        if (!isset($this->_timing_stop_times[$name])) {
30            $stop_time = explode(' ', microtime());
31        } else {
32            $stop_time = $this->_timing_stop_times[$name];
33        }
34       
35        // Do the big numbers first so the small ones aren't lost.
36        $current = $stop_time[1] - $this->_timing_start_times[$name][1];
37        $current += $stop_time[0] - $this->_timing_start_times[$name][0];
38       
39        return sprintf($this->time_format, $current);
40    }
41}
42
43?>
Note: See TracBrowser for help on using the repository browser.