Re: Benchmark modifications > fixed typos > 3rd time lucky
| From: | Richard | Date: | Sun, 27 Oct 2002 17:26:56 +0000 |
| Subject: | Re: Benchmark modifications > fixed typos > 3rd time lucky | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-10295@lists.php.net to get a copy of this message | ||
--- Timer.php Mon Oct 28 02:44:14 2002 +++ Timer.new Mon Oct 28 03:16:15 2002 @@ -60,6 +60,14 @@ var $markers = array(); /** + * Number of decimal places of time elapsed + * + * @var int + * @access private + */ + var $_precision; + + /** * Auto-start and stop timer * * @var boolean @@ -80,12 +88,13 @@ * * @access public */ - function Benchmark_Timer($auto = false) { + function Benchmark_Timer($auto = false, $precision = 6) { $this->PEAR(); if ($auto) { $this->auto = $auto; $this->start(); } + $this->_precision = $precision; } /** @@ -96,9 +105,31 @@ function _Benchmark_Timer() { if ($this->auto) { $this->stop(); - $this->display(); } } + + /** + * Sets precision of the time difference. + * + * @param int number of decimal places precision + * @access public + */ + function setPrecision($precision) + { + if ((is_int($precision)) && ($precision > 0)) { + $this->_precision = $precision; + } + } + + /** + * Gets precision of the time difference. + * + * @access public + */ + function getPrecision() + { + return $this->_precision; + } /** * Return formatted profiling information. @@ -205,7 +236,7 @@ */ function timeElapsed($start = 'Start', $end = 'Stop') { if (extension_loaded('bcmath')) { - return bcsub($this->markers[$end], $this->markers[$start], 6); + return bcsub($this->markers[$end], $this->markers[$start], $this->_precision); } else { return $this->markers[$end] - $this->markers[$start]; } @@ -228,8 +259,8 @@ foreach ($this->markers as $marker => $time) { if (extension_loaded('bcmath')) { - $diff = bcsub($time, $temp, 6); - $total = bcadd($total, $diff, 6); + $diff = bcsub($time, $temp, $this->_precision); + $total = bcadd($total, $diff, $this->_precision); } else { $diff = $time - $temp; $total = $total + $diff;