note 36101 added to function.microtime

From: Date: Thu, 25 Sep 2003 17:41:18 +0000
Subject: note 36101 added to function.microtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-57131@lists.php.net to get a copy of this message
// Here's a useful class that will take care of your script timing in seconds/milliseconds. class Script_Timer { function Script_Timer () { return true; } function Start_Timer () { define ("TIMER_START_TIME", microtime()); return true; } function Get_Time ($decimals=2) { // $decimals will set the number of decimals you want for your milliseconds. // format start time $start_time = explode (" ", TIMER_START_TIME); $start_time = $start_time[1] + $start_time[0]; // get and format end time $end_time = explode (" ", microtime()); $end_time = $end_time[1] + $end_time[0]; return number_format ($end_time - $start_time, $decimals); } } // You can use: define ("TIMER_START_TIME", microtime()); // in your program config file (or somewhere it will always get set), or you can use this explicitly where you want to start the timer: Script_Timer::Start_Timer(); // A constant definition is used so the starting time can be retrieved from anywhere. // When you want to retrieve the time difference (from start to finish) use: $total_time = Script_Timer::Get_Time(3); // The $decimals argument is optional and will default to 2 ---- Manual Page -- http://www.php.net/manual/en/function.microtime.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36101 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36101&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36101&report=yes

« previous php.notes (#57131) next »