Changeset 479 for trunk/lib/ScriptTimer.inc.php
- Timestamp:
- May 3, 2014 11:09:03 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/ScriptTimer.inc.php
r468 r479 31 31 private $_timing_cumulative_times = array(); 32 32 33 34 33 public function start($name='default') 34 { 35 35 $this->_timing_start_times[$name] = explode(' ', microtime()); 36 37 38 39 40 41 42 43 36 } 37 38 public function stop($name='default') 39 { 40 if (!isset($this->_timing_stop_times[$name]) || !isset($this->_timing_cumulative_times[$name])) { 41 $this->_timing_stop_times[$name] = null; 42 $this->_timing_cumulative_times[$name] = null; 43 } 44 44 $this->_timing_stop_times[$name] = explode(' ', microtime()); 45 45 $this->_timing_cumulative_times[$name] += $this->getTime($name); 46 47 48 49 46 } 47 48 public function getTime($name='default') 49 { 50 50 if (!isset($this->_timing_start_times[$name])) { 51 51 return 0; 52 52 } 53 53 if (!isset($this->_timing_stop_times[$name])) { … … 60 60 $current += $stop_time[0] - $this->_timing_start_times[$name][0]; 61 61 return $current; 62 63 64 65 66 67 68 69 70 71 72 73 74 62 } 63 64 public function printAll($sort_by_time=false) 65 { 66 $names = array_map('strlen', array_keys($this->_timing_start_times)); 67 sort($names); 68 $name_len = end($names); 69 70 if ($sort_by_time) { 71 arsort($this->_timing_cumulative_times, SORT_NUMERIC); 72 } 73 74 $this->_timing_cumulative_times['TOTAL'] = array_sum($this->_timing_cumulative_times); 75 75 76 76 echo '<pre>'; 77 78 79 77 foreach ($this->_timing_cumulative_times as $name => $time) { 78 printf("\n%-{$name_len}s $this->time_format", $name, $time); 79 } 80 80 echo '</pre>'; 81 81 } 82 82 }
Note: See TracChangeset
for help on using the changeset viewer.