Search by

stougeiro / bench

stougeiro

Simple Bench β€” a lightweight, dependency-free exploratory benchmark harness for PHP libraries.

Package info

github.com/stougeiro/bench

pkg:composer/stougeiro/bench

Fund package maintenance!

Buymeacoffee

Statistics

Installs: 33

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v0.2.0 2026-12-03 21:52 UTC

This package is auto-updated.

Last update: 2026-12-03 22:13:12 UTC


README

English | PortuguΓͺs

PHP PHPStan-Level Pest-php License

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 Scenario object β€” 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.