stougeiro / bench
Simple Bench β a lightweight, dependency-free exploratory benchmark harness for PHP libraries.
Fund package maintenance!
Requires
- php: ^8.3
Requires (Dev)
- pestphp/pest: ^3.8
- phpstan/phpstan: ^2.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-03 22:13:12 UTC
README
Simple Bench
A lightweight, dependency-free exploratory benchmark harness for PHP libraries. It measures scenarios, reports comparable metrics, and helps identify bottlenecks and evaluate security/performance tradeoffs.
Simple Bench is intentionally not a CI gate. It has no thresholds and never fails because a number changed.
π Detailed guide: USAGE.md
β¨ Features
- Simple
Scenarioobject β setup, run, teardown, iterations, samples, and optional scenarios in one readable value. - Comparable metrics β average, median, p95, min/max, ops/sec, peak memory, and memory delta.
- Human and JSON output β tables for exploration, JSON for baselines.
- Baseline comparison β compare runs on the same machine and PHP version.
- Optional scenarios β skip expensive or side-effect-heavy scenarios.
- No runtime dependencies β uses only PHP's timing and memory functions.
π¦ Installation
composer require --dev stougeiro/bench
π Quick start
Create bench/scenarios.php:
<?php declare(strict_types=1); use STDW\Bench\Scenario; return [ 'example.operation' => Scenario::make( iterations: 10_000, samples: 5, warmup: 100, run: static fn (mixed $state, int $i): mixed => some_operation(), ), ];
Add a Composer script:
"scripts": { "bench": "@php vendor/bin/bench --scenarios=bench/scenarios.php --package=your/package" }
Run:
composer bench composer bench -- --filter=example composer bench -- --json composer bench -- --save=bench-baseline.json composer bench -- --baseline=bench-baseline.json
Scenario shape
'name' => Scenario::make( run: static fn (mixed $state, int $i): mixed => operation($state), setup: static fn (): mixed => prepare(), teardown: static fn (mixed $state): void => cleanup($state), iterations: 1000, samples: 5, warmup: 10, optional: false, ),
setup and teardown run outside the measured window. Use them for temporary
directories, handlers, fixtures, and cleanup.
See USAGE.md for lifecycle details, fixtures, repeated scenarios, baseline comparison, and the agent workflow.
π§ Why?
Performance work needs a starting point, not a premature gate. Simple Bench provides a small, predictable way to measure scenarios and compare runs without adding a benchmark framework or forcing thresholds into CI.
π€ Contributions
Contributions are welcome. Feel free to open issues or submit pull requests.