Simple and precise benchmarking for PHP 8.4+. Measures execution time and memory usage of code blocks with minimal overhead.
- High-precision time and memory measurement
- Clean and readable syntax for benchmarking code blocks
- Support for named measurements and grouped runs
- Easy integration via callable or closure wrapping
- Fluent API for accessing results
- Minimal overhead, suitable for micro-benchmarking
- Native support for PHP 8.4+ features
- Integrates with Tracy for real-time benchmark visualization
composer require matraux/php-benchmark
version | PHP | Note |
---|---|---|
1.0.7 | 8.3+ | Initial commit |
1.1.0 | 8.4+ | Property access, performance optimizations |
1.1.1 | 8.4+ | Bugfixes and formatting improvements |
1.2.0 | 8.4+ | Integrations into Bridge/Tracy |
1.3.0 | 8.4+ | Added Symfony Console integration |
See Tracy, Standalone or Console integration for advanced instructions.
use Matraux\PhpBenchmark\Benchmark\Benchmark;
$benchmark = Benchmark::create();
$benchmark->label = 'Memory peak 20 MB';
$benchmark->counter = 10;
$benchmark->multiplier = 2;
$measurement = $benchmark->run(function (): string {
return str_repeat(' ', 20 * 1024 * 1024);
});
echo $measurement->average; // Print average time (e.g. 44 ms)
echo $measurement->memory; // Print peak memory usage (e.g. 22 MB)
See Development for debug, test instructions, static analysis, and coding standards.
For bug reports and feature requests, please use the issue tracker.