![]() You can pass the closure function which you want to benchmark as the first argument. … \Illuminate\Support\Benchmark::measure(Closure|array $benchmarkables, int $iterations) This class has measure() and dd() methods. You can use all methods that are described above, but Laravel also has a Benchmark utility class since version 9.32.0. Next, let’s have a look at how to check the execution time PHP in Laravel. "\n" //prints time in milliseconds and peak memory usage in MB as stringĮcho $event->getMemory(). Then, you can use the Symfony\Component\Stopwatch\Stopwatch class to measure execution time:Įcho (string) $event. Install the package using the following command: composer require symfony/stopwatch It is a standalone package that allows to get execution time in milliseconds and memory usage in a straightforward way without any extra calculations. $duration = Carbon::now()->getTimestampMs() - $start Let’s have a look at the example of measurement: Also, you can use the format() method, but note that this method returns a string: You can measure the execution time in nanoseconds using this code: If you pass true as the first argument, you will get an integer with the number of nanoseconds: Just save the current time in the $start variable in beginning of your script or code, and then get the timestamp in the end of your script or code and calculate the difference: ![]() If this precision is enough for you, use the time() function to measure the execution time of a PHP script. It returns the number of seconds that have passed since January 1, 1970, 00:00:00 GMT. PHP language has the time() function that allows you to get the current timestamp in seconds. It’s also worth mentioning how all these units of time are related to each other: Time
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |