php 使用Benchmark对代码进行测试

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);
?>

转载于:https://my.oschina.net/zyj622/blog/117338

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值