microtime()
返回当前时间的微秒级表示。
microtime(bool $as_float = false): string|float
参数
| 参数 | 类型 | 说明 |
|---|---|---|
$as_float | bool | true 返回浮点数,false 返回字符串 |
返回值
string|float — 浮点数或「微秒 秒」格式的字符串。
示例
$t = microtime(true);
// ... 业务
printf('耗时 %.2f ms', (microtime(true) - $t) * 1000);输出
耗时 0.03 ms
注意
- 传 true 才能直接做减法,传 false 得到的是字符串,需要 explode。
- 它是测量代码耗时的标准做法,比 time() 精确。