http://www.12xl.cn/index.php/post/191.html
在写PHP项目的时候,发现速度很慢,于是查看一下是哪里影响的。
- <?php
- // 实例1
-
- /**
- * @start time
- */
- function proStartTime() {
- global \$startTime;
- \$mtime1 = explode(" ", microtime());
- \$startTime = \$mtime1[1] + \$mtime1[0];
- }
-
- /**
- * @End time
- */
- function proEndTime() {
- global \$startTime,\$set;
- \$mtime2 = explode(" ", microtime());
- \$endtime = \$mtime2[1] + \$mtime2[0];
- \$totaltime = (\$endtime - \$startTime);
- \$totaltime = number_format(\$totaltime, 7);
- echo "process time: ".\$totaltime."\r\n";
- }
-
- // 程序调用开始记时
- proStartTime();
-
- sleep(1); // sleep() 延时代码执行若干秒
- proEndTime(); // 程序在每一段所消耗的执行时间
- sleep(2);
- proEndTime();
- sleep(3);
- proEndTime();
-
-
- /************************************************* 华丽的分割线 **************************************************/
-
- // 实例2
-
- \$t1 = microtime(true);
- sleep(3);
- \$t2 = microtime(true);
- echo '程序耗时'.round(\$t2-\$t1,3).'秒';
-
- ?>