Skip to content

How to Benchmark Your Code in Laravel 9.32+

laravel benchmark

With the release of Laravel 9.32, the Benchmark helper was introduced.

 

The measure() static method takes in a Closure and outputs the execution time in milliseconds.

We can also pass an array of Closures:

We can also optionally specify how many iterations the Closures should run.
This will give us the average execution time:


Last but not least, theBenchmark Class has a dd() method.

Happy coding 😊


Let me know what you think about this article in the comments section below.

If you find this article helpful, please share it with others and subscribe to the blog to support me, and receive a bi-monthly-ish e-mail notification on my latest articles.   
  

Comments