学习、分享、快乐
当前位置 >> 68楼学习网学习教育电脑学习编程入门PHP教程测试PHP代码运行速度的函数

测试PHP代码运行速度的函数

[08-23]   来源:http://www.68lou.com  PHP教程   阅读:149

测试PHP代码运行速度的函数,本站还有更多关于PHP教程,PHP技巧,php培训,php学习,php安装的文章。
正文:

通常为了优化代码,我们需要一种可以测试代码运行时间的方法,从而来选择最优的代码。

下面的函数可以测试运行代码所需的时间: 
function ss_timing_start ($name = default) { 
global $ss_timing_start_times; 
$ss_timing_start_times[$name] = explode( , microtime()); 

function ss_timing_stop ($name = default) { 
global $ss_timing_stop_times; 
$ss_timing_stop_times[$name] = explode(, microtime()); 

function ss_timing_current ($name = default) { 
global $ss_timing_start_times, $ss_timing_stop_times; 
if (!isset($ss_timing_start_times[$name])) { 
return 0; 

if (!isset($ss_timing_stop_times[$name])) { 
$stop_time = explode(, microtime()); 

else { 
$stop_time = $ss_timing_stop_times[$name]; 

$current = $stop_time[1] - $ss_timing_start_times[$name][1]; 
$current += $stop_time[0] - $ss_timing_start_times[$name][0]; 
return $current; 

现在可以轻松地检查任何一段代码的执行时间了,甚至我们可以同时使用多个计时器,只需在使用上述的几个函数时设定不同的参数作为计时器的名称就可以了。。。现在知道 如何测试PHP代码运行速度的函数了吧。




如果觉得测试PHP代码运行速度的函数不错,可以推荐给好友哦。
Tag:PHP教程PHP技巧,php培训,php学习,php安装电脑学习 - 编程入门 - PHP教程