Make Timings and TimingPoint implement Stringable.

This commit is contained in:
flash 2025-04-03 15:18:36 +00:00
parent 6f9ab9136e
commit 16e9676430
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E
3 changed files with 22 additions and 5 deletions

View file

@ -1 +1 @@
0.2504.31450
0.2504.31518

View file

@ -1,14 +1,16 @@
<?php
// TimingPoint.php
// Created: 2022-02-16
// Updated: 2025-02-27
// Updated: 2025-04-03
namespace Index\Performance;
use Stringable;
/**
* Represents a timing point.
*/
class TimingPoint {
class TimingPoint implements Stringable {
/**
* @param int $timePoint Starting tick count.
* @param int $duration Duration tick count.
@ -30,4 +32,14 @@ class TimingPoint {
public int|float $durationTime {
get => $this->duration / PerformanceCounter::frequency();
}
public function __toString(): string {
$string = $this->name;
if(!empty($this->comment))
$string .= sprintf(';desc="%s"', rawurlencode($this->comment));
$string .= sprintf(';dur=%.5f', $this->durationTime);
return $string;
}
}

View file

@ -1,16 +1,17 @@
<?php
// Timings.php
// Created: 2022-02-16
// Updated: 2025-02-27
// Updated: 2025-04-03
namespace Index\Performance;
use InvalidArgumentException;
use Stringable;
/**
* Represents a Stopwatch with timing points.
*/
class Timings {
class Timings implements Stringable {
public private(set) Stopwatch $stopwatch;
private int $lastLapTicks;
@ -74,4 +75,8 @@ class Timings {
$comment
);
}
public function __toString(): string {
return implode(', ', $this->laps);
}
}