We now have quite a good option with the new implementation of dd() method. So, since Laravel 9.32.0 you can easily test the performance of any part of your Laravel application. Just add new “Benchmark” class and you will be able the time it takes (in milliseconds) for the certain callbacks to complete:
<?php use App\Models\User; use Illuminate\Support\Benchmark; Benchmark::dd(fn () => User::find(1)); // 0.1 ms Benchmark::dd([ 'Scenario 1' => fn () => User::count(), // 0.5 ms 'Scenario 2' => fn () => User::all()->count(), // 20.0 ms ]); ?>
You can also measure the average execution time if you specify the number of iterations like that:
Benchmark::dd(fn () => User::count(), iterations: 10); // 0.5 ms
Here is the official documentation on the topic.
P.S: Taylor Otwell, the founder of Laravel: “No more hunting down rogue dumps!”