Download the PHP package kaniosx/phpunit-performance-profiler without Composer
On this page you can find all versions of the php package kaniosx/phpunit-performance-profiler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kaniosx/phpunit-performance-profiler
More information about kaniosx/phpunit-performance-profiler
Files in kaniosx/phpunit-performance-profiler
Package phpunit-performance-profiler
Short Description A lightweight memory and execution time profiler for PHPUnit and Pest.
License MIT
Informations about the package phpunit-performance-profiler
PHPUnit Performance Profiler
A lightweight memory and execution time profiler for PHPUnit and Pest. Turn performance budgets into simple, first-class assertions inside your existing test suite — no external profiling tools or infrastructure required.
Requirements
- PHP >= 8.2
- PHPUnit ^10.0 || ^11.0
Installation
Usage
Add the AssertsPerformance trait to your test case (or a shared base test case) and call
the assertion methods with the code you want to measure:
assertMemoryPeakUnder(float $maxMegabytes, callable $callback, string $message = '')
Fails if peak memory usage while running $callback exceeds $maxMegabytes.
assertExecutionTimeUnder(float $maxMilliseconds, callable $callback, string $message = '')
Fails if $callback takes longer than $maxMilliseconds to run.
Both methods throw InvalidArgumentException if the given budget is not a positive number,
and accept an optional custom $message to override the default failure message.
Using the profiler directly
If you need raw metrics instead of an assertion (e.g. to log them, or to assert on both
memory and time from a single execution), call Profiler::run() directly:
Profiler::run() returns a ProfileResult with:
| Property | Type | Description |
|---|---|---|
durationSeconds |
float |
Wall-clock execution time of the callback, in seconds. |
memoryUsageBytes |
int |
Net memory retained after the callback ran. |
memoryPeakBytes |
int |
Peak memory usage recorded since process start (see note below). |
Note:
memoryPeakBytesreflects PHP's process-wide peak memory usage (memory_get_peak_usage()), not just the peak during the callback. If something earlier in the same process allocated more memory than your callback does, that earlier peak is what you'll see. Run performance-sensitive tests in isolation (e.g.@runInSeparateProcess) if you need a clean baseline.
Running the tests
License
This package is licensed under the MIT License.