1.下载Benchmark包
2.使用方法:
<?php
require ('Benchmark/Timer.php');
$timer = new Benchmark_Timer();
$timer->start();
$timer->stop();
$timer->setMarker('Marker name');
$timer->display();
?>
执行如下:
4.测试代码运行效率
<?php
/**
* This page performs benchmarks on a function.
* This page requires the REAR Benchmark package.
*/
//Function to be tested:
function dummy() {
$data = 'This is some text.';
echo '<!--<h1>echo() with single quotes</h1>
<table border="0" width="90%" cellspacing="3" cellpadding="3" align="center">
<tr>
<td>'.$data.'</td>
<td>'.$data.'</td>
<td>'.$data.'</td>
</tr>
<tr>
<td>'.$data.'</td>
<td>'.$data.'</td>
<td>'.$data.'</td>
</tr>
</table>
<p>End of echo() width single quotes.</p>-->
';
}
//Include the Iterate class definition:
require ('Benchmark/Iterate.php');
//Create and start an iteration:
$b = new Benchmark_Iterate();
$b->run(100, 'dummy');
//Get the results:
$r = $b->get();
//Print the results:
echo "<h1>Results:{$r['iterations']} iterations of the dummy() <br/>function took an average of {$r['mean']} seconds.</h1>";
//Delete the object:
unset($b);
?>