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";  
  • 相关阅读:
    GITHUB常见命令
    GITHUB常用命令
    java构建简单的HTTP服务器
    是否会被锁
    GITHUB使用指南
    GITHUB使用指南、
    C#
    金蝶后台表对应
    金蝶K3表
    nodejs nodejs的操作
  • 原文地址:https://www.cnblogs.com/Jerry-blog/p/5038788.html
Copyright © 2011-2022 走看看