Skip to content

Commit

Permalink
Stats: convert TimingMetric usage of microtime() to hrtime()
Browse files Browse the repository at this point in the history
Per PHP docs, hrtime() is recommended for performance measurements.

Bug: T245464
Change-Id: I233f18faaeaccf70360e828383442abf036a1997
  • Loading branch information
shdubsh committed Oct 12, 2023
1 parent 236fa50 commit 74cf32f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions includes/libs/Stats/Metrics/TimingMetric.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct( $baseMetric, $logger ) {
* @return void
*/
public function start(): void {
$this->startTime = microtime( true );
$this->startTime = hrtime( true );
}

/**
Expand All @@ -83,7 +83,8 @@ public function stop(): void {
trigger_error( "Stats: stop() called before start() for metric '{$this->getName()}'", E_USER_WARNING );
return;
}
$this->observe( ( microtime( true ) - $this->startTime ) * 1000 );
$value = ( hrtime( true ) - $this->startTime ) * 1e+6; // convert nanoseconds to milliseconds
$this->observe( $value );
$this->startTime = null;
}

Expand Down

0 comments on commit 74cf32f

Please sign in to comment.