Home  >  Article  >  Backend Development  >  PHP容易性能检测类工具

PHP容易性能检测类工具

WBOY
WBOYOriginal
2016-06-13 13:05:58956browse

PHP简单性能检测类工具

一、概述
 该类主要是检测一段代码的运行时间,检测一些PHP效率问题。

二、使用方法
首先require该类
主要使用接口为begin(),preTime()和end()
begin($output, $environment)
该接口主要负责检测初始位置,当执行该接口时,就代表着检测开始。
preTime()
该接口主要是检测上一次代码执行时间
end()
该接口主要是检测总的执行时间

三、举例
  1. require "run_time_test.php";  
  2.   
  3. Run_Time_Test::begin(true);  
  4.   
  5. $a = "";  
  6. $b = "";  
  7. for($i=0; $i$i++){  
  8.     $a .= $i;   
  9. }  
  10.   
  11. Run_Time_Test::preTime();  
  12.   
  13. for($i=0; $i$i++){  
  14.     $b .= $i;   
  15. }  
  16.   
  17. Run_Time_Test::end();  

加载该工具类,同时设置检测起始位置,同时在代码中添加多个Run_Time_Test::preTime();检测每个阶段的代码执行效率,最后输出总的运行时间。

四、主要用途
可以在PHP的入口添加begin和输出处添加end,在需要测试效率处添加两个Run_Time_Test::preTime();进行检测,将执行结果记录到info log中。从而查看代码的执行效率,特别是一些算法执行过程中。

测试代码以及类点击此处
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn