• 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
  • 相关阅读:
    关于以追加模式写入文件时,为什么第一行是空行?
    使用正则表达式的技巧
    super关键字的三种用法
    Excel快捷键
    重载与重写的区别
    方法重名
    区分子类方法中重名的三种变量
    继承
    Chapter08【String类、static、Arrays类、Math类】
    Math类
  • 原文地址:https://www.cnblogs.com/wangbin/p/1864484.html
Copyright © 2020-2023  润新知