dragon-code/benchmark
Lightweight PHP benchmarking helper to compare execution speed of multiple callbacks. Run named tests, repeat iterations, trim outliers for cleaner averages, and print results (min/max/avg/total + memory) to the console. Includes bench() helper and Benchmark class.
microtime() or third-party tools) lack regression testing, warmup, or deviation analysis.array_search vs. custom binary search).toAssert() + toBeRegressionTime).spatie/laravel-feature-management).Adopt if:
bench or Python’s timeit).Look elsewhere if:
perf.For Executives: "This package lets us automate performance testing like we do for unit tests—catching slowdowns before they hit production. For example, we can compare two database query strategies and enforce a 10% speed threshold in CI. This reduces tech debt in high-traffic areas (e.g., checkout flows) and aligns with our goal to [reduce latency by X%]. It’s a lightweight, open-source alternative to paid tools like Blackfire, with the added benefit of regression detection."
For Engineers:
*"Think of this as PHP’s assert() for performance:
toAssert()->toBeRegressionTime(max: 15) to your tests to block slowdowns.Example workflow:
// In a test or script:
Benchmark::make()
->warmup(3) // Account for OPcache
->iterations(100)
->compare(
'Eloquent': fn () => User::find(1),
'Raw SQL': fn () => DB::select('SELECT * FROM users WHERE id = 1')[0],
)
->toAssert()
->toBeAvgTime(from: 0, till: 5); // Fail if avg > 5ms
Outcome: Data to justify refactoring or optimize, with zero manual timing code."*
How can I help you explore Laravel packages today?