略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: HRTime\StopWatch::getElapsedTime

2024-12-20

HRTime\StopWatch::getElapsedTime

(PECL hrtime >= 0.4.3)

HRTime\StopWatch::getElapsedTimeGet elapsed time for all intervals

说明

public HRTime\StopWatch::getElapsedTime(int $unit = ?): float

Get elapsed time for all the previously closed intervals.

参数

unit

Time unit represented by a HRTime\Unit constant. Default is HRTime\Unit::SECOND.

返回值

Returns float indicating elapsed time.

add a noteadd a note

User Contributed Notes 1 note

up
0
j_jaberi at yahoo dot com
2 years ago
As not mentioned, if used with invalid unit value, it uses default one:

<?php
        $stopWatch
= new HRTime\StopWatch();
       
$stopWatch->start();
        for(
$i=0; $i<10000000; $i++);
       
$stopWatch->stop();
        echo
$stopWatch->getElapsedTime(-1) . ' - ' .
       
$stopWatch->getElapsedTime(0) . ' - ' .
       
$stopWatch->getElapsedTime(1) . ' - ' .
       
$stopWatch->getElapsedTime(2) . ' - ' .
       
$stopWatch->getElapsedTime(3) . ' - ' .
       
$stopWatch->getElapsedTime(4);
?>
Outputs soething like:
0.11936771 - 0.11936771 - 119.36771 - 119367.71 - 119367710 - 0.11936771

官方地址:https://www.php.net/manual/en/hrtime-stopwatch.getelapsedtime.php

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