前言
可以在网页指定位置显示加载完页面所耗间,虽然看起来很傻屌,但对于喜欢优化速度的朋友自己看起来还是很方便,不用每次打开控制台看时间。
代码
- 把代码复制到主题目录functions.php最后面。
/**
* 加载所耗时间
*/
function timer_start() {
global $timestart;
$mtime = explode( ' ', microtime() );
$timestart = $mtime[1] + $mtime[0];
return true;
}
timer_start();
function timer_stop( $display = 0, $precision = 3 ) {
global $timestart, $timeend;
$mtime = explode( ' ', microtime() );
$timeend = $mtime[1] + $mtime[0];
$timetotal = number_format( $timeend - $timestart, $precision );
$r = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s";
if ( $display ) {
echo $r;
}
return $r;
}
- 在要展示的地方添加下面的代码
Loading:<?php echo timer_stop();?>
后记
以上操作完成后保存刷新就可以了看到效果了。如果报错,肯定是你操作不对。
PS
文章内容收集自网络
万水千山总是情,给个打赏行不行。
打赏
