Top

Timer Class


PHP Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  6.3 (of 3 scores)
Date Added  Feb 18, 2006
Last Updated  Feb 18, 2006

Introduction

A Timer that checks how long a script / function / query took to run

Grab the Code

<?php
/*
Timer Class by Shahir Ali (da^hype)
URL: http://www.codedb.org
 
Usage:
$timer = new Timer;
$timer->start_time();
 
sleep(5); //sleep for a while
 
$timer->end_time();
echo "Script ran in: ";
echo $timer->elapsed_time();
echo " seconds."; 
*/
 
//Timer class
class Timer
{
 
 var $stime; //value of start time
 var $etime; //value of end time
 
 //default constructor
 function Timer()
 {
       $this->stime = 0.0;
 }
 
 function get_microtime()
 {
      $tmp = explode(" ",microtime());
      $rtime = (double)$tmp[0] + (double)$tmp[1];
      return $rtime;
 }
 
 function start_time()
 {
     $this->stime = $this->get_microtime();
 }
 
 function end_time()
 {
     $this->etime = $this->get_microtime();
 }
 
 function elapsed_time($decimal = 3)
 {
     return round(($this->etime - $this->stime),$decimal);
 } 
 
}
?> 

Comments

  (0)  RSS

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom