Benchmarking tool

Benchmark function with rounded precision, works in PHP4/5

<?php

function benchmark($start_time=false,$precision=4)
{
	list($usec, $sec) = explode(" ", microtime());
	if ($start_time) 
		return round((((float)$usec + (float)$sec) - (float)$start_time),$precision);
	else
		return round(((float)$usec + (float)$sec),$precision);		
}

/*
$start = benchmark();
// This is the place where your code goes
usleep(10000);
echo benchmark($start); // 0.0106, your results will vary
*/

?>

Usage

Refer to the commented section of code for usage. $precision is how many decimal places rounds off the end of the float, the default is pretty good.


Comments

Add your comment