zoukankan      html  css  js  c++  java
  • 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
    ?>


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

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

    清晰代码的执行效率。

  • 相关阅读:
    css 三角形
    转盘
    使用history.back()出现"警告: 网页已过期的解决办法"
    jQuery 左侧滑动
    Go语言数组的使用
    Go的变量作用域
    Go语言中函数的实现
    Go语言循环判断的使用~
    Go基础
    go环境的安装~
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/3935322.html
Copyright © 2011-2022 走看看