略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Basic usage

2025-02-27

Basic usage

The example illustrates the basic StopWatch class usage

示例 #1 Measure several code blocks execution and get the total

<?php

$c
= new HRTime\StopWatch;

$c->start();
/* measure this code block execution */
for ($i = 0; $i < 1024*1024; $i++);
$c->stop();
$elapsed0 = $c->getLastElapsedTime(HRTime\Unit::NANOSECOND);

/* measurement is not running here*/
for ($i = 0; $i < 1024*1024; $i++);

$c->start();
/* measure this code block execution */
for ($i = 0; $i < 1024*1024; $i++);
$c->stop();
$elapsed1 = $c->getLastElapsedTime(HRTime\Unit::NANOSECOND);

$elapsed_total = $c->getElapsedTime(HRTime\Unit::NANOSECOND);

?>
添加备注

用户贡献的备注

此页面尚无用户贡献的备注。

官方地址:https://www.php.net/manual/en/hrtime.example.basic.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3