note 33448 added to function.microtime

From: Date: Thu, 26 Jun 2003 12:40:37 +0000
Subject: note 33448 added to function.microtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-51036@lists.php.net to get a copy of this message
using the microtime function is possibly one of the worst ways to calculate execution time. I give two examples, of which are much more precise. 1. gettimeofday -- calculate time passed using the sec and usec var of gettimeofday() 2. unix 'date' command -- calculate time passed using the nanosecond and second variables. -- code example -- $start1=gettimeofday(); list($start2, $start3) = explode(":", exec('date +%N:%S')); // insert your script here $end1=gettimeofday(); $totaltime1 = (float)($end1['sec'] - $start1['sec']) + ((float)($end1['usec'] - $start1['usec'])/1000000); list($end2, $end3) = explode(":", exec('date +%N:%S')); $totaltime2 = (float)($end3 - $start3) + ((float)($end2 - $start2)/1000000000); echo "$totaltime2\n"; echo "$totaltime1\n"; -- end code example -- You'd be surprised at how accurate these functions are, and if you don't believe me, run php on the commandline using the time command 'time php script.php' -- it will print to stdout, but you'll see script execution time. peace, kenny ---- Manual Page -- http://www.php.net/manual/en/function.microtime.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33448 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33448&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33448&report=yes

« previous php.notes (#51036) next »