matraux / php-benchmark
There is no license information available for the latest version (2.0.0) of this package.
Benchmarking tool for PHP 8.4+ to measure code performance with accurate time and memory profiling.
2.0.0
2025-07-25 21:29 UTC
Requires
- php: ^8.4
Requires (Dev)
- contributte/qa: ^0.3.2
- nette/neon: ^3.4
- nette/tester: ^2.5
- nette/utils: ^4.0
- phpstan/phpstan: ^2.1
- tracy/tracy: ^2.10
Suggests
- nette/utils: Required only if you use Tracy
- tracy/tracy: Required only if you use Tracy
README
Introduction
Simple and precise benchmarking for PHP 8.4+. Measures execution time and memory usage of code blocks with minimal overhead.
Features
- 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
Installation
composer require matraux/php-benchmark
Requirements
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 |
Examples
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)
Development
See Development for debug, test instructions, static analysis, and coding standards.
Support
For bug reports and feature requests, please use the issue tracker.