You have a function and you want to see how long it takes to execute.
Compare time in milliseconds before running the function against the time in milliseconds after running the function to see the elapsed time spent in the function itself:
<?php // create a long nonsense string $long_str = uniqid(php_uname('a'), true); // start timing from here $start = microtime(true); // function to test $md5 = md5($long_str); $elapsed = microtime(true) - $start; echo "That took $elapsed seconds.\n"; ?>
To determine how much time a single function takes to execute, you may not need a full benchmarking package like PEAR Benchmark (which is covered in Recipe 21.2). Instead, you can get the information you need from the microtime( ) function.
21.1.4. See Also
Using microtime( ), including how it works in PHP 4, is discussed in Recipe 3.13; documentation on the microtime( ) function is at http://www.php.net/microtime; Recipe 21.2 looks at PEAR Benchmark.