Page 1 of 1

Performance Measurement

Posted: Fri Oct 06, 2006 9:01 am
by ngungo
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;
}

Posted: Fri Oct 06, 2006 9:50 am
by kaszu
Check http://uk.php.net/microtime first example

Posted: Fri Oct 06, 2006 10:26 am
by ngungo

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?

Posted: Fri Oct 06, 2006 11:26 am
by DaveTheAve
ngungo wrote:

Code: Select all

echo "Did nothing in $time seconds\n";
Reminds me of M$. lol