• microtime() 测试代码执行时间,提高编码效率


    <?php
    $b_time = microtime(true);
    $a = array("1","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2","2","1","2","1","2","1","2","1","2","1","2");
    $count = 0;
    foreach ($a as $key => $value) {
     foreach ($a as $key => $value) {
      foreach ($a as $key => $value) {
       $b = 1*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8*1*8*8;
       //$count++;
      }
     }
    }
    $e_time = microtime(true);
    $taketime = $e_time-$b_time;
    //echo $taketime;
    echo $taketime;
    //3.5078401565552
    //0.68016886711121
    //15.500303983688
    ?>


    它能精确到很细微的时间。不仅仅是秒。

    在代码执行体首尾加上,可以检测执行的时间情况。

    清晰代码的执行效率。

  • 相关阅读:
    Excel Sheet Column Number
    Compare Version Numbers
    Min Stack
    Excel Sheet Column Title
    Find Peak Element
    数据规范化
    Majority Element
    用户唯一登录
    面试总结——Java高级工程师(三)
    Spring AOP 实战运用
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/3935322.html
Copyright © 2020-2023  润新知