PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ngungo
Forum Commoner
Posts: 75 Joined: Thu Jun 08, 2006 10:45 pm
Post
by ngungo » Fri Oct 06, 2006 9:01 am
I try to measure how long a server takes to perform a routine using following function. It does not seem right since it uses an absolute time clock instead of a "cpu clock". Comment, please. Other methods?
Code: Select all
$_start = microtime();
...
blah blah blah
...
$t = number_format(diff_microtime($_start,microtime()), 2);
echo $t;
function diff_microtime($mt_old,$mt_new) {
list($old_usec, $old_sec) = explode(' ',$mt_old);
list($new_usec, $new_sec) = explode(' ',$mt_new);
$old_mt = ((float)$old_usec + (float)$old_sec);
$new_mt = ((float)$new_usec + (float)$new_sec);
return $new_mt - $old_mt;
}
kaszu
Forum Regular
Posts: 749 Joined: Wed Jul 19, 2006 7:29 am
Post
by kaszu » Fri Oct 06, 2006 9:50 am
ngungo
Forum Commoner
Posts: 75 Joined: Thu Jun 08, 2006 10:45 pm
Post
by ngungo » Fri Oct 06, 2006 10:26 am
Code: Select all
/**
* Simple function to replicate PHP 5 behaviour
*/
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
// Sleep for a while
usleep(100);
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "Did nothing in $time seconds\n";
They look just about the same, I think. Is that right?
DaveTheAve
Forum Contributor
Posts: 385 Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:
Post
by DaveTheAve » Fri Oct 06, 2006 11:26 am
ngungo wrote:
Code: Select all
echo "Did nothing in $time seconds\n";
Reminds me of M$. lol