phpTimer.class.php
2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/*******************************************************************************
phpTimer: A simple script to time script execution
Copyright (C) 2001 Roger Raymond ~ epsilon7@users.sourceforge.net
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*******************************************************************************/
if(!defined('_PHP_TIMER_INCLUDED')) define('_PHP_TIMER_INCLUDED',1);
class phpTimer {
function phpTimer ()
{ $this->_version = '0.1';
$this->_enabled = true;
}
function start ($name = 'default')
{ if($this->_enabled)
{ $this->_timing_start_times[$name] = explode(' ', microtime());
}
}
function stop ($name = 'default')
{ if($this->_enabled)
{ $this->_timing_stop_times[$name] = explode(' ', microtime());
}
}
function get_current ($name = 'default')
{ if($this->_enabled)
{ if (!isset($this->_timing_start_times[$name]))
{ return 0;
}
if (!isset($this->_timing_stop_times[$name]))
{ $stop_time = explode(' ', microtime());
}
else
{ $stop_time = $this->_timing_stop_times[$name];
}
// do the big numbers first so the small ones aren't lost
$current = $stop_time[1] - $this->_timing_start_times[$name][1];
$current += $stop_time[0] - $this->_timing_start_times[$name][0];
return sprintf("%.10f",$current);
}
else
{ return 0;
}
}
}