dragon-code/benchmark
Benchmark is a small PHP dev tool for quickly comparing execution speed of different code paths. Use the bench() helper or Benchmark class, pass callbacks (named or not), and print results to the console for easy side-by-side timing.
composer require dragon-code/benchmark --dev — it's a dev-only dependency intended for local performance validation.bench() helper function:
use function DragonCode\Benchmark\bench;
bench()->compare(
fn() => strlen('foo'),
fn() => mb_strlen('foo')
)->toConsole();
array_map vs foreach, Eloquent vs raw DB queries).compare() to give meaningful labels ('fast' => fn()..., 'slow' => fn()...), improving output clarity.->iterations(500) to gather more stable stats when measuring small differences; avoid over-measuring by keeping iterations realistic.->beforeEach(fn() => $this->seedTestCache()) to ensure fair conditions across iterations.->deviations(5) to assess stability — e.g., measure database call times across multiple runs to detect flakiness.->benchmark()->compare(...)->toArray()) for CI validation or comparison logs.total / iterations equals per-call overhead unless iterations = 1.avg excludes top/bottom 10% of results — this improves stability but may hide outliers. Verify deviation patterns if suspicious.beforeEach/afterEach callbacks return values get passed into the main callback — useful for injecting per-iteration state (e.g., random seeds).iteration param is passed only when explicitly typed: fn(int $i) => ....round() affects only display — use round(0) for integer-style timing output, but keep raw values for comparisons.->iterations(-10) → treats as 10. Safe, but confusing — prefer positive values for clarity.parallel unless isolating single-threaded behavior.->compare(fn() => null, fn() => null) first) if profiling tiny snippets (<1ms).How can I help you explore Laravel packages today?