21.1.1. ProblemYou have a function and you want to see how long it takes to execute. 21.1.2. SolutionCompare 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"; ?> 21.1.3. DiscussionTo 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 AlsoUsing 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. |