最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
使用xhprof在开发环境中测试php性能
时间:2015-01-21 编辑:简简单单 来源:一聚教程网
以百分之一的概率产生测试数据,尽量不影响正式环境效率。
class XHProf {
// private $XHProfPath = ‘xhprof/’;
private $XHProfPath = ‘/usr/local/apache/htdocs/xhprof/’;
private $applicationName = ‘sias_application’;
private $sampleSize = 100;
private static $enabled = false;
public function XHProf_Start() {
if (mt_rand(1, $this->sampleSize) == 1) {
include_once $this->XHProfPath . ‘xhprof_lib/utils/xhprof_lib.php’;
include_once $this->XHProfPath . ‘xhprof_lib/utils/xhprof_runs.php’;
xhprof_enable(XHPROF_FLAGS_NO_BUILTINS + XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
self::$enabled = true;
}
}
public function XHProf_End() {
if (self::$enabled) {
$XHProfData = xhprof_disable();
$XHProfRuns = new XHProfRuns_Default();
$XHProfRuns->save_run($XHProfData, $this->applicationName);
}
}
}
测试效果:
Overall Summary
Total Incl. Wall Time (microsec): 48,162 microsecs
Total Incl. CPU (microsecs): 32,994 microsecs
Total Incl. MemUse (bytes): 2,773,464 bytes
Total Incl. PeakMemUse (bytes): 2,867,664 bytes
Number of Function Calls: 749
从以下测试结果看出,耗时最多的居然是连接数据库,所以我们来尽量优化数据库。
相关文章
- PHP SPL标准库 SplFixedArray 介绍及和Array的性能测试 04-19
- php 防跨站攻击测试例子(供学习使用) 07-03
- Yaf框架与PHPUnit的集成测试 03-01
- php set_time_limit()用法测试详解 08-24
- php soap 调用webservice应用测试 06-18
- php测试性能代码 07-21