php 计算代码执行时间

对于脚本语言的执行时间, 一直都在谈。

PHP的很多的框架实现所谓的bench_mark的来表示自己的执行时间不高之类的。

 

其实对普通的PHP程序也可以看代码的执行时间。

 

 

 

[php] view plain copy
 
  1. class runtime  
  2. {  
  3.     var $StartTime = 0;  
  4.     var $StopTime = 0;  
  5.    
  6.     function get_microtime()  
  7.     {  
  8.         list($usec, $sec) = explode(' ', microtime());  
  9.         return ((float)$usec + (float)$sec);  
  10.     }  
  11.    
  12.     function start()  
  13.     {  
  14.         $this->StartTime = $this->get_microtime();  
  15.     }  
  16.    
  17.     function stop()  
  18.     {  
  19.         $this->StopTime = $this->get_microtime();  
  20.     }  
  21.    
  22.     function spent()  
  23.     {  
  24.         return round(($this->StopTime - $this->StartTime) * 1000, 1);  
  25.     }  
  26.    
  27. }  

 

 

比如:

 

[php] view plain copy
 
  1. $run_time = new runtime();  
  2. $run_time->start();  
  3. //begin your code  
  4. //end your code  
  5. $run_time->stop();  
  6. echo "Script running time:".$run_time->spent()."ms";  

 

转载于:https://www.cnblogs.com/Jerry-blog/p/5038788.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值