phpunit/php-timer
Lightweight timing utility extracted from PHPUnit. Start/stop a timer to get a Duration with formatted time plus seconds, milliseconds, microseconds, and nanoseconds. Includes resource usage formatting (time + memory) for a measured block or since request start.
Install the package with composer require phpunit/php-timer. Import the SebastianBergmann\Timer\Timer class and start/stop timing around any code block. The most immediate use case is benchmarking critical paths — e.g., testing the performance of database queries, API calls, or algorithmic changes during development or in CI. Start by calling $timer->start(), run your code, then call $timer->stop() to get a Duration object with human-readable (asString()) and numeric (asSeconds(), asMilliseconds(), etc.) representations.
ResourceUsageFormatter.resourceUsageSinceStartOfRequest() to prepend timing and memory stats to responses for performance monitoring (especially useful in staging/development).composer require phpunit/php-timer:^8.asNanoseconds() — avoid nanosecond precision for operations > ~4 seconds unless on 64-bit.$_SERVER['REQUEST_TIME_FLOAT'] (used by resourceUsageSinceStartOfRequest()) is unreliable in CLI or when using SAPIs that don’t set it; prefer explicit start()/stop() for accuracy.ResourceUsageFormatter or build your own wrapper to inject performance metrics into logs or structured reporting (e.g., JSON in health checks).Duration comparisons in unit tests — e.g., $this->assertTrue($duration->asSeconds() < 0.1) — but be sure to warm up the JVM (if applicable) and run tests in isolation to reduce noise.How can I help you explore Laravel packages today?