// the find
sebastianbergmann/php-timer
Utility class for timing
php-timer is a micro-library extracted from PHPUnit that wraps hrtime for measuring elapsed durations. It returns a typed Duration object rather than a raw float, which is the only real design decision here. If you're writing a CLI tool or test harness and want formatted time output without pulling in a stopwatch library, this is it.
Duration is a proper value object with explicit unit accessors (asSeconds, asMilliseconds, asNanoseconds) — no guessing what unit the float is in. ResourceUsageFormatter bundles memory reporting alongside time in one call, which is genuinely useful for test runners. PHPStan at max level plus strict rules means the tiny API surface is type-clean. Maintained actively by Bergmann with a real CI pipeline and API surface checks.
The star count (7744) is almost entirely PHPUnit's coattails — this is a transitive dependency most people have never directly required. There's no support for laps or split times, so anything beyond a single start/stop needs you to manage multiple Timer instances yourself. ResourceUsageSinceStartOfRequest relies on REQUEST_TIME_FLOAT, which the README itself calls unreliable — it silently breaks in CLI contexts where that superglobal isn't set. At three classes and two exceptions, there's not much here that `hrtime(true)` and a subtraction wouldn't cover in five lines.