- How do I install dragon-code/benchmark in a Laravel project?
- Run `composer require dragon-code/benchmark --dev` in your project root. The package is development-only and won’t affect production builds. No Laravel-specific setup is required beyond installation.
- Can I use this package in Laravel 8, 9, or 10?
- Yes, the package supports PHP 8.0+, which aligns with Laravel 8+. No Laravel-specific dependencies exist, so it works across all supported Laravel versions without conflicts.
- What’s the difference between the `bench()` helper and the `Benchmark` class?
- Both provide identical functionality. Use `bench()` for concise syntax (e.g., `bench()->compare(...)`) or instantiate the `Benchmark` class directly (e.g., `new Benchmark()` or `Benchmark::make()`). Choose based on preference.
- Does this package work in production, or is it dev-only?
- This is a **development-only** tool. Avoid using it in production environments. It’s designed for local performance profiling and lacks production-grade validation (e.g., memory leak checks or race condition handling).
- How accurate are the benchmark results for Laravel-specific code?
- Results are accurate for isolated code comparisons but may vary in complex Laravel environments (e.g., with service container overhead, caching, or database interactions). Test in a staging-like setup for reliable insights.
- What does the ‘top and bottom 10% exclusion’ feature do?
- When running 9+ iterations, the package discards the slowest and fastest 10% of results to reduce noise from external factors (e.g., system load). This improves average accuracy for cleaner comparisons.
- Are there alternatives like spatie/laravel-benchmark that integrate better with Laravel?
- Yes, alternatives like `spatie/laravel-benchmark` offer Laravel-specific features (e.g., service container integration or database-aware benchmarks). However, `dragon-code/benchmark` is lighter and framework-agnostic if you need simplicity.
- How do I benchmark Laravel route handlers or middleware?
- Extract the logic into standalone closures or methods, then pass them to `bench()->compare()`. Avoid benchmarking full HTTP requests, as they include network overhead. For middleware, test individual handler logic separately.
- Is this package actively maintained? Should I use it for critical performance tuning?
- Maintenance is unclear—the last release (4.6.1) was in 2026 with no recent commits. Use it for exploratory testing, but validate results against other tools (e.g., Xdebug or Blackfire) for mission-critical decisions.
- Can I extend or customize the benchmark output format?
- The package provides a `toConsole()` method for tabular output, but customization requires extending the `Benchmark` class or forking the package. No built-in hooks exist for modifying output directly.