devster/ubench
Ultra small PHP benchmarking library with a simple API to time code, measure memory usage, run iterations, and print readable results. Great for quick micro-benchmarks in scripts, tests, and CLI tools without dependencies.
Start by installing via Composer: composer require --dev devster/ubench. Create a Benchmark instance at the top of your test script or inline in code you want to profile. Use start() before the block and stop() after — the class stores the interval and memory delta automatically. For the first real use, benchmark a trivial operation (e.g., string concatenation vs. implode()) and call getReport() to see formatted output. Check the examples/ folder in the repo (if available) or inspect Benchmark::start(), Benchmark::stop(), and Benchmark::getReport() signatures in the source.
Benchmark in your test suite’s development/test runner to assert performance thresholds (e.g., ensure a utility function never exceeds 2ms for typical inputs).implode() for quick side-by-side analysis.getReport() output into your dev-mode logging (e.g., info() with Monolog) to catch accidental slowdowns in local dev.->getElapsedMicroseconds() and ->getMemoryDelta() in assertions to prevent regressions (e.g., $this->assertLessThan(0.001, $bench->getElapsedSeconds())).getPeakMemoryUsage() instead of raw delta for stable measurements.for loop). Consider wrapping Benchmark in a simple BenchmarkRunner utility.microtime(true) usages may need explicit float casting in newer PHP versions.Benchmark instance, call reset() to clear previous runs — don’t rely on re-instantiation in tight loops.How can I help you explore Laravel packages today?