• php获取页面执行时间


     1 <?php
     2 
     3 class runtime
     4 {
     5 
     6     
     7     function __construct() {
     8     $db_config = array(
     9     'host' => '127.0.0.1',
    10     'port' => 3306,
    11     'user' => 'root',
    12     'pwd' => 'root',
    13     'dbname' => 'test'
    14     );
    15     $link = mysql_connect($db_config['host'], $db_config['user'], $db_config['pwd']);
    16     if (!$link) {
    17         die('Could not connect: ' . mysql_error());
    18     }
    19     mysql_query("set names 'utf8'");
    20     mysql_select_db($db_config['dbname'], $link) or die('Can\'t use foo : ' . mysql_error());
    21     }
    22     
    23     var $StartTime = 0;
    24     var $StopTime = 0;
    25     function get_microtime()
    26     {
    27     list($usec, $sec) = explode(' ', microtime());
    28     return ((float)$usec + (float)$sec);
    29     }
    30     function start()
    31     {
    32     $this->StartTime = $this->get_microtime();
    33     }
    34     function stop()
    35     {
    36     $this->StopTime = $this->get_microtime();
    37     }
    38     function spent()
    39     {
    40         $total = ($this->StartTime-$this->StopTime);
    41         return round($total * 1000, 1);
    42     }
    43 }
    44 
    45 
    46 $runtime= new runtime;
    47 $runtime->start();//计时开始//中间放置需要计时的函数或过程
    48 //for($i=1;$i<=1000;$i++)
    49 //{
    50 //  $id="100";
    51 //  $username="xm";
    52 //  //$this->conn = new Mysql($db_config);
    53 //  //$sql="INSERT INTO tb_user(id,name) values('$id','$username')";
    54 //  //mysql_query($sql);
    55 //}
    56   for ($i=1; $i<=1000;$i++) {  
    57       $id = '100';   
    58       $username = 'xm';   
    59       $sql[] = '('.$id.',"'.$username.'")';  
    60  } 
    61  mysql_query('INSERT INTO tb_user(id,name) values '.implode(',',$sql)); 
    62 $runtime->stop();//计时结束
    63 echo "页面执行时间:".$runtime->spent()."毫秒";
  • 相关阅读:
    Ubuntu在命令行开启远程桌面
    Qt5编译项目出现GL/gl.h:No such file or directory错误
    硬盘录像机协议与技术汇总
    js判断IP字符串是否正确
    PHP获取原生POST数据
    hdu 5093 二分匹配
    hdu 4435 bfs+贪心
    hdu 4431 绝对值之和最小公式
    hdu 5073 推公式相邻质心转换
    hdu 3657 最小割(牛逼!!!!)总算理解了
  • 原文地址:https://www.cnblogs.com/lh460795/p/2983568.html
Copyright © 2020-2023  润新知