| [ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 /* Reminder: always indent with 4 spaces (no tabs). */ 4 // +---------------------------------------------------------------------------+ 5 // | Geeklog 1.3 | 6 // +---------------------------------------------------------------------------+ 7 // | timer.class.php | 8 // | Geeklog timer class. Use this to do performance testing. | 9 // | | 10 // +---------------------------------------------------------------------------+ 11 // | Copyright (C) 2000-2002 by the following authors: | 12 // | | 13 // | Authors: Tony Bibbs, tony@tonybibbs.com | 14 // +---------------------------------------------------------------------------+ 15 // | | 16 // | This program is free software; you can redistribute it and/or | 17 // | modify it under the terms of the GNU General Public License | 18 // | as published by the Free Software Foundation; either version 2 | 19 // | of the License, or (at your option) any later version. | 20 // | | 21 // | This program is distributed in the hope that it will be useful, | 22 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 23 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 24 // | GNU General Public License for more details. | 25 // | | 26 // | You should have received a copy of the GNU General Public License | 27 // | along with this program; if not, write to the Free Software Foundation, | 28 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 29 // | | 30 // +---------------------------------------------------------------------------+ 31 // 32 // $Id: timer.class.php,v 1.7 2004/03/30 02:41:34 vinny Exp $ 33 34 /* EXAMPLE USAGE 35 36 // Instantiate new timer object 37 $mytimer = new timerobject(); 38 39 // Set percision of the results to 4 significan't digits 40 // NOTE: this call is optional, code defaults to 2 41 $mytimer->setPercision(4); 42 43 // Start the timer 44 $mytimer->startTimer(); 45 46 // Stop timer and print elapsed time 47 echo $mytimer->endTimer(); 48 49 */ 50 51 /** 52 * This class is used to time program execution. This is particularly handy for 53 * performance trouble shooting. 54 * 55 * @author Tony Bibbs 56 * 57 */ 58 class timerobject { 59 60 // PRIVATE PROPERTIES 61 62 /** 63 * @access private 64 */ 65 var $_starttime = ''; 66 /** 67 * @access private 68 */ 69 var $_endtime = ''; 70 /** 71 * @access private 72 */ 73 var $_elapsedtime = ''; 74 /** 75 * @access private 76 */ 77 var $_percision = 2; 78 79 // PUBLIC METHODS 80 81 /** 82 * Constructor 83 * 84 * This initializes the timerobject and sets the default 85 * percision of results to two decimal places 86 * 87 */ 88 function timerobject() 89 { 90 } 91 92 /** 93 * Set percision on timer results 94 * 95 * This sets how many significant digits get 96 * sent back when elapsedTime is called 97 * 98 * @param int $num_dec_places Number of significant digits 99 * 100 */ 101 function setPercision($num_dec_places) 102 { 103 $this->_percision = $num_dec_places; 104 } 105 106 /** 107 * Starts the timer 108 * 109 */ 110 function startTimer() 111 { 112 $mtime = microtime(); 113 $mtime = explode(' ', $mtime); 114 $mtime = $mtime[1] + $mtime[0]; 115 $this->_starttime = $mtime; 116 } 117 118 /** 119 * Stops the timer 120 * 121 * @return float elapsed time to degree of percision specified 122 * 123 */ 124 function stopTimer() 125 { 126 $mtime = microtime(); 127 $mtime = explode(' ',$mtime); 128 $mtime = $mtime[1] + $mtime[0]; 129 $this->_endtime = $mtime; 130 $this->_setElapsedTime(); 131 132 // We are going to assume that when the timer is stopped 133 // they will want the elapsed time immediately 134 return $this->getElapsedTime(); 135 } 136 137 /** 138 * Restarts the timer 139 * 140 * Same as starTimer excepts this clears everything out first 141 * 142 */ 143 function restart() 144 { 145 $this->_endtime = ''; 146 $this->_elapsedtime = ''; 147 148 $this->startTimer(); 149 } 150 151 /** 152 * Gets the elapsed time 153 * 154 * This returns the elapsed time with the proper number of 155 * significant digits 156 * 157 * @return float Elasped time in seconds formatted to degree of percision specified 158 * 159 */ 160 function getElapsedTime() 161 { 162 return sprintf("%.{$this->_percision}f", $this->_elapsedtime); 163 } 164 165 // PRIVATE METHODS 166 167 /** 168 * Sets the elapsed time 169 * 170 * once stop timer is called this gets called to calculate 171 * the elapsed time for later retrieval 172 * 173 * @access private 174 */ 175 function _setElapsedTime() 176 { 177 $this->_elapsedtime = $this->_endtime - $this->_starttime; 178 } 179 180 } 181 182 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
|