Skip to content

Benchmarking tool for PHP 8.4+ to measure code performance with accurate time and memory profiling.

License

Notifications You must be signed in to change notification settings

matraux/php-benchmark

Repository files navigation

MATRAUX PHP Benchmark

Latest Version on Packagist Last release License: MIT PHP Security Policy Contributing QA Status Issues Last Commit


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.

About

Benchmarking tool for PHP 8.4+ to measure code performance with accurate time and memory profiling.

Resources

License

Security policy

Stars

Watchers

Forks