zoukankan      html  css  js  c++  java
  • php 计算代码执行时间

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

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

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

    [php] view plaincopy
     
    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 plaincopy
     
    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";  
  • 相关阅读:
    JS
    Python之缩进块
    Python快捷键
    Python介绍
    SOAP UI-----测webservice接口
    jmeter分布式压测(多台电脑一起压测)
    jmeter操作数据库
    jmeter压测
    jmeter关联
    jmeter参数化
  • 原文地址:https://www.cnblogs.com/Jerry-blog/p/5038788.html
Copyright © 2011-2022 走看看