dragon-code/benchmark
dragon-code/benchmark is a simple PHP benchmarking package for comparing code execution speed across multiple options. Use bench() or Benchmark with named closures and view min, max, avg, and total timings in the console. Install via Composer as a dev dependency.
array_map vs. foreach, cache driver X vs. Y, JSON vs. serialized payloads, eager vs. lazy loading — the fluent bench()->compare(foo: ..., bar: ...) API lets an engineer produce a defensible, reproducible comparison (min/max/avg/total, time and memory) in minutes rather than days.toAssert() with toBeAvgTime, toBeTotalTime, toBeMaxMemory thresholds turns "fast enough" from a vibe into a numeric, reviewable spec that can be negotiated with stakeholders and encoded in CI.toBeRegressionTime / toBeRegressionMemory feature is the highest-leverage capability here. It converts performance from a periodic audit into a per-PR constraint, which directly supports a roadmap commitment like "no more than N% latency regression per release."deviations()) provide a cheap noise/volatility signal — useful when deciding whether an optimization is real or measurement variance, which shapes whether a refactor gets scheduled at all.toData() returning DTOs means results can feed dashboards, PR comments, or release notes — relevant if you want performance visibility for non-engineers.Adopt when:
--dev-only tool with zero production footprint.Look elsewhere when:
Adoption caveats to plan for: 121 stars and zero known dependents is thin social proof; the value is real but the ecosystem signal is weak. Treat the library as a thin, replaceable utility and keep benchmark files isolated so a swap is cheap.
To executives: It is a free, MIT-licensed developer tool that installs only in development and never ships to production. For roughly an afternoon of setup, we get two things: a fast, standard way for engineers to prove which of two implementations is faster before committing to it, and an automated check that fails a pull request if a code change makes a critical path measurably slower. That converts performance from an occasional fire drill into a routine, low-cost guardrail attached to the work we already do.
To engineering: One dev dependency, a fluent API, and a console table you can paste into a PR. bench()->compare(foo: ..., bar: ...) for ad-hoc comparison; toAssert() for numeric budgets; warmup() and automatic trimming of the top/bottom 10% of iterations (above nine iterations) for cleaner numbers; toBeRegressionTime/Memory with committed .snap baselines to catch regressions in CI. toData() gives DTOs if you want to wire results into reporting. Caveats to state plainly: these are microbenchmarks — they measure the code you give them, not user-perceived latency; CI runner noise can swamp small deltas, so set tolerances generously and re-baseline deliberately; and snapshots must be committed and owned, or the gate becomes a nuisance that people disable.
Risk framing: Single maintainer, modest adoption, but MIT-licensed, dev-only, and small enough that forking is a weekend, not a quarter. The decision is reversible at near-zero cost, which is precisely why it is worth trying before investing in bespoke tooling.
How can I help you explore Laravel packages today?