php 计时器类:

 

 
  
  1. class timer 
  2.     var $time_start
  3.     var $time_end
  4.      
  5.     function __construct() 
  6.     { 
  7.        $this->time_start = 0; 
  8.        $this->time_end = 0; 
  9.     } 
  10.      
  11.     function timer() 
  12.     { 
  13.        $this->__construct(); 
  14.     } 
  15.      
  16.     function start() 
  17.     { 
  18.        list($usec,$sec) = explode(" ",microtime()); 
  19.        $this->time_start = (float)$usec + (float)$sec
  20.     } 
  21.      
  22.     function stop() 
  23.     { 
  24.        list($usec,$sec) = explode(" ",microtime()); 
  25.        $this->time_end = (float)$usec + (float)$sec
  26.     } 
  27.      
  28.     function show($output = false) 
  29.     {  
  30.        $total = $this->time_end - $this->time_start; 
  31.        if ($output) { 
  32.         echo $total," sec"
  33.         return true; 
  34.        } 
  35.        return $total." sec"
  36.     }