今天,为了测试一断程序的运行时间,特意写了这么一个类,并添加了注释,希望对大家有所帮助
类很简单,主要是运用了几个函数数组列表函数list(),字符串分割成数组函数explode(),获取时间戳和微秒数microtime(),代码如下:
代码如下:
class runTime {
private $starTime;//开始时间
private $stopTime;//结束时间
private function getMicTime(){
$mictime=microtime();//获取时间戳和微秒数
list($usec,$sec)=explode(" ",$mictime);//把微秒数分割成数组并转换成变量处理
return (float)$usec+(float)$sec;//把转换后的数据强制用浮点点来处理
}
public function star(){//获取开始时间
$this->starTime=$this->getMicTime();
}
public function stop(){//获取结束时间
$this->stopTime=$this->getMicTime();
}
public function spent(){//计算程序持续时间
return round($this->stopTime-$this->starTime)*1000;//获取毫秒数
}
}
//举例
$time=new runTime();
$time->star();
for ($i=1;$iecho("a");
}
$time->stop();
echo $time->spent();
?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks agoByDDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks agoByDDD
Where to find the Crane Control Keycard in Atomfall
3 weeks agoByDDD
Assassin's Creed Shadows - How To Find The Blacksmith And Unlock Weapon And Armour Customisation
1 months agoByDDD
Roblox: Dead Rails - How To Complete Every Challenge
3 weeks agoByDDD

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools