zoukankan      html  css  js  c++  java
  • PHP计算程序运行时间的类

    1 class timer {
    2  var $StartTime = 0;
    3 var $StopTime = 0;
    4 var $TimeSpent = 0;
    5 function start(){
    6 $this->StartTime = microtime();
    7 }
    8 function stop(){
    9 $this->StopTime = microtime();
    10 }
    11 function spent() {
    12 if ($this->TimeSpent) {
    13 return $this->TimeSpent;
    14 } else {
    15 $StartMicro = substr($this->StartTime,0,10);
    16 $StartSecond = substr($this->StartTime,11,10);
    17 $StopMicro = substr($this->StopTime,0,10);
    18 $StopSecond = substr($this->StopTime,11,10);
    19 $start = doubleval($StartMicro) + $StartSecond;
    20 $stop = doubleval($StopMicro) + $StopSecond;
    21 $this->TimeSpent = $stop - $start;
    22 return substr($this->TimeSpent,0,8)."";
    23 }
    24 }
    25 }//end class timer;
    26
    27
    28 $timer = new timer;
    29 $timer->start();
    30 $temp=0;
    31 for($i=0;$i<10000;$i++) for($j=0;$j<$i;$j++) $temp ++;
    32 $timer->stop();
    33 echo "循环 $temp 次,运行时间为 ".$timer->spent();

    1 //脚本运行时间
    2  $start_time = array_sum(explode(" ",microtime()));
    3 $run_time = array_sum(explode(" ",microtime())) - $start_time;
    4  echo('<center>Script Run Time: '.$run_time.'</center>');

    aliyun活动 https://www.aliyun.com/acts/limit-buy?userCode=re2o7acl
  • 相关阅读:
    Codeforces Round #610 (Div. 2)C(贪心,思维)
    Educational Codeforces Round 80 (Rated for Div. 2)C(DP)
    BZOJ2190 仪仗队
    BZOJ3613 南园满地堆轻絮
    BZOJ1084 最大子矩阵
    BZOJ1036 树的统计Count
    BZOJ1452 Count
    BZOJ2242 计算器
    BZOJ2705 Longge的问题
    BZOJ1509 逃学的小孩
  • 原文地址:https://www.cnblogs.com/wangbin/p/1864484.html
Copyright © 2011-2022 走看看