PHP code example of alexandrebulete / laravel-benchmark
1. Go to this page and download the library: Download alexandrebulete/laravel-benchmark library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alexandrebulete / laravel-benchmark example snippets
class UserProcessingBenchmark extends BenchmarkCase
{
// Auto-set by --code option, creates "benchmark:users"
protected static ?string $code = 'users';
// Define CLI options
protected static array $options = [
'count' => ['default' => 1000, 'description' => 'Number of users'],
];
protected function applyOptions(array $options): void
{
$this->count = $options['count'];
}
public function benchmark(): void
{
// Your benchmark logic
}
}
'iterations' => [
// Default number of iterations
'default' => env('BENCHMARK_ITERATIONS', 5),
// Bounds
'min' => 1,
'max' => 100,
// Default warmup runs
'warmup' => env('BENCHMARK_WARMUP', 0),
// Show individual run times
'show_individual' => true,
// Warn if variance exceeds this %
'variance_warning_threshold' => 15,
],
class MyBenchmark extends BenchmarkCase
{
// Disable for this specific benchmark
protected bool $withAdvisor = false;
// Or disable at runtime
public function benchmark(): void
{
$this->withAdvisor(false);
}
}
'advisor' => [
'enabled' => true,
'rules' => [
'n_plus_one' => [
'enabled' => true,
'threshold' => 10, // Min similar queries to flag
'critical_count' => 100, // Count for critical severity
'critical_time_ms' => 1000, // Time for critical severity
],
'slow_query' => [
'enabled' => true,
'threshold_ms' => 100, // Warning threshold
'critical_ms' => 1000, // Critical threshold
],
'hotspot' => [
'enabled' => true,
'threshold_percent' => 50, // % of queries/time
'min_queries' => 10, // Min queries to analyze
],
'duplicate' => [
'enabled' => true,
'threshold' => 2, // Min duplicates to flag
],
],
],