Download the PHP package alexandrebulete/laravel-benchmark without Composer
On this page you can find all versions of the php package alexandrebulete/laravel-benchmark. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alexandrebulete/laravel-benchmark
More information about alexandrebulete/laravel-benchmark
Files in alexandrebulete/laravel-benchmark
Package laravel-benchmark
Short Description A comprehensive benchmark system for Laravel applications
License MIT
Informations about the package laravel-benchmark
Laravel Benchmark
A comprehensive benchmark system for Laravel applications. Safely test performance with isolated database, automatic cleanup, production protection, dynamic command generation, and intelligent optimization suggestions.
Features
- π Production Safe - Automatically disabled in production environment
- ποΈ Isolated Database - Separate benchmark database to avoid data pollution
- π Detailed Metrics - Execution time, memory usage, and peak memory tracking
- π³ Docker Ready - Includes Docker Compose template for benchmark database
- π οΈ Artisan Commands - Easy-to-use CLI for creating and running benchmarks
- π§Ή Auto Cleanup - Database is wiped after each benchmark
- β‘ Dynamic Commands - Auto-generate CLI commands with custom options
- π§ Advisor - Automatic N+1 detection, slow query alerts, and optimization suggestions
- π Baseline & Regression - Save baselines and detect performance regressions
- π Multiple Iterations - Run benchmarks multiple times for stable, statistically meaningful results
Requirements
- PHP 8.2 or higher
- Laravel 10, 11, or 12
Installation
Then run the installation command:
Quick Start
1. Create a benchmark with a command code
2. Define CLI options in your benchmark
3. Run your benchmark
π Multiple Iterations - Stable & Reliable Results
By default, benchmarks run 5 iterations to provide statistically stable results. This eliminates variance from garbage collection, CPU cache, and other system factors.
Why Multiple Iterations?
A single benchmark run can be misleading due to:
- βοΈ Cold cache on first run
- ποΈ Garbage collection pauses
- π» CPU scheduling variations
- π I/O fluctuations
Running multiple iterations and using the median provides much more reliable results.
Sample Output
Controlling Iterations
Warmup Runs
Warmup runs execute the benchmark but discard results - useful for:
- Filling CPU caches
- JIT compilation warmup
- Database connection pooling
Statistics Provided
| Metric | Description |
|---|---|
| Average | Mean of all runs |
| Median | Middle value (used for baselines) |
| Min / Max | Range of results |
| Std Deviation | Variance measure (Β±value and %) |
| P95 / P99 | 95th/99th percentile |
| Stability | Assessment based on variance |
Stability Grades:
Very Stable(< 5% variance)Stable(< 10% variance)Moderate Variance(< 20% variance)High Variance(> 20% variance)
Configuration
In config/benchmark.php:
High Variance Warning
When results are unstable, you'll see a warning:
This helps you know when your benchmark environment may be affecting results.
π§ Advisor - Intelligent Query Analysis
The Advisor automatically analyzes all SQL queries during your benchmark and provides actionable optimization suggestions.
What it detects
| Rule | Description |
|---|---|
| N+1 Queries | Same query pattern executed multiple times |
| Slow Queries | Individual queries exceeding time threshold |
| Hotspots | Code locations generating most DB activity |
| Duplicates | Exact same queries executed multiple times |
Sample Output
Performance Score
The Advisor calculates a Performance Score (0-100) based on:
| Factor | Impact |
|---|---|
| N+1 queries | -8 to -15 per issue |
| Slow queries | -10 to -20 per issue |
| High DB time (>70%) | -10 to -15 |
| Low query uniqueness | -5 to -15 |
| Bonuses | +5 to +10 for clean code |
Grades:
- π A (90-100): Excellent
- β B (80-89): Good
- β οΈ C (70-79): Acceptable
- π§ D (60-69): Needs Work
- β E (50-59): Poor
- π΄ F (0-49): Critical
Smart Suggestions
The Advisor analyzes your SQL to provide specific eager loading suggestions:
Instead of generic advice, it detects the table and suggests the exact relationship name.
Disabling Advisor
Or globally via environment:
Configuring Thresholds
In config/benchmark.php:
Dynamic Commands
The killer feature! Define $code and $options in your benchmark class, and a CLI command is automatically generated.
This auto-creates:
List all available benchmarks and their codes:
Configuration
After installation, customize settings in config/benchmark.php:
Environment Variables
Docker Setup
Creating Benchmarks
Full Example
Running
π Baseline & Regression Detection
Track performance over time and detect regressions before they reach production.
Save a Baseline
Save current benchmark results as a reference point using --baseline:
Note: Baselines store the median execution time from all iterations - the most stable metric for comparisons.
Compare Against Baseline
Run benchmark and compare to saved baseline using --compare:
Regression Detection
When performance degrades:
CI/CD Integration
Export results as JSON and fail builds on critical regressions:
In your CI pipeline (GitHub Actions example):
List Saved Baselines
Configure Thresholds
In config/benchmark.php:
Available Commands
| Command | Description |
|---|---|
benchmark:install |
Install the package (config, directories, Docker) |
benchmark:list |
List all available benchmarks with codes |
benchmark:run {name} |
Run a benchmark by class name |
benchmark:{code} |
Run a benchmark with custom options (auto-generated) |
benchmark:{code} --iterations=N |
Run N iterations (default: 5) |
benchmark:{code} --warmup=N |
Discard first N runs as warmup |
benchmark:{code} --baseline |
Run and save results as baseline |
benchmark:{code} --compare |
Run and compare against baseline |
benchmark:{code} --fail-on-regression |
Fail on critical regression (CI) |
benchmark:baselines |
List all saved baselines |
make:benchmark {name} |
Create a new benchmark class |
make:benchmark {name} --code={code} |
Create a benchmark with dynamic command |
make:benchmark-seeder {name} |
Create a new benchmark seeder |
Security
Multiple safety measures:
- Environment Check: Commands refuse to run in production
- Config Flag:
BENCHMARK_ENABLEDmust betrue - Separate Database: Uses isolated database connection
- Auto Cleanup: Database is wiped after each benchmark
- Docker Isolation: Benchmark database runs in separate container
License
MIT License - see LICENSE for details.
Author
- Alexandre Bulete - [email protected]
All versions of laravel-benchmark with dependencies
illuminate/console Version ^10.0 || ^11.0 || ^12.0
illuminate/contracts Version ^10.0 || ^11.0 || ^12.0
illuminate/database Version ^10.0 || ^11.0 || ^12.0
illuminate/support Version ^10.0 || ^11.0 || ^12.0
spatie/laravel-package-tools Version ^1.16