Using Benchmarks with simple code

Using  Benchmarks with simple code

If you want to test a particular aspect of your code without having to worry about the HTTP overhead, you can benchmark using the microtime(), which returns the current time accurate to the microsecond as a string. The following function will convert it into a number suitable for calculations.

function getmicrotime()
{
list($usec, $sec) = explode(” “,microtime());
return ((float)$usec + (float)$sec);
}

$time = getmicrotime();

#
# benchmark code here
#

echo “

Time elapsed: “,getmicrotime() - $time, ” seconds”;

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.