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