36 lines
720 B
PHP
36 lines
720 B
PHP
<?php
|
|
|
|
namespace App\Service\Performance;
|
|
|
|
class PerformanceTrackerService
|
|
{
|
|
private ?float $startTime = null;
|
|
private ?float $endTime = null;
|
|
|
|
public function start(): void
|
|
{
|
|
$this->startTime = microtime(true);
|
|
$this->endTime = null;
|
|
}
|
|
|
|
public function stop(): void
|
|
{
|
|
$this->endTime = microtime(true);
|
|
}
|
|
|
|
public function getDurationMs(): int
|
|
{
|
|
if (!$this->startTime) {
|
|
return 0;
|
|
}
|
|
|
|
$endTime = $this->endTime ?? microtime(true);
|
|
return (int)round(($endTime - $this->startTime) * 1000);
|
|
}
|
|
|
|
public function reset(): void
|
|
{
|
|
$this->startTime = null;
|
|
$this->endTime = null;
|
|
}
|
|
} |