<?php 
define("GETTIME", '$timer->gettime()'); 
class timer{ 
   var $times; 
   function getmicrotime(){ 
      list($usec, $sec) = explode(" ",microtime()); 
      return ((float)$usec + (float)$sec); 
   } 
   function timer(){ 
      $this->times['total']["start"] = $this->getmicrotime(); 
   } 
   function start($name){ 
      echo "<hr>Starting $name<hr>\n"; 
      $this->times[$name]["start"] = $this->getmicrotime(); 
      unset($this->times[$name]["stop"]); 
   } 
   function stop($name, $decimals = 10){ 
      if( isset($this->times[$name]['start']) ){ 
         $this->times[$name]["stop"] = $this->getmicrotime(); 
         return number_format($this->times[$name]["stop"]-$this->times[$name]["start"],$decimals); 
      }else{ 
         echo "<hr>$name is not set<hr>\n"; 
      } 
   } 
   function getextratime($decimals = 10){ 
      $timetotal = 0; 
      while( list( $k) = each( $this->times)){ 
         if( $k != 'total' ) $timetotal += (int)$this->gettime($k); 
      } 
      reset($this->times); 
      return number_format($this->gettime("total") - $timetotal, $decimals); 
   } 
   function gettime($name = "total", $decimals = 10){ 
      if( !isset($this->times[$name]["stop"]) ){ 
         return number_format($this->getmicrotime() - $this->times[$name]["start"],$decimals); 
      }else{ 
         return number_format($this->times[$name]["stop"] - $this->times[$name]["start"],$decimals); 
      } 
   } 
   function showtimes($decimals = 10, $format = "%name: %time<br>\n"){ 
      while( list( $k, $v) = each($this->times)){ 
         echo str_replace(array("%name", "%time"), array($k, $this->gettime($k,$decimals)), $format); 
      } 
      reset($this->times); 
   } 
} 
?>