Home > Article > Backend Development > Speed optimization - PHP program execution efficiency problem
One of the methods in my controller has a long piece of code logic, I won’t post the specific code. The main thing I want to ask you is how can I know how long it takes each time I execute this method and what the execution speed is!
One of the methods in my controller has a long piece of code logic, I won’t post the specific code. The main thing I want to ask you is how can I know how long it takes each time I execute this method and what the execution speed is!
Thank you for the invitation. In fact, it is very simple. You only need to output two times at the entrance and end of your method. Subtract the start time from the end time to get the program execution time! Right? Of course, you need to pay special attention to it. You need to use microseconds for better comparison. php
subtle reference microtime
You can use this method at the beginning and end, just find the difference
<code>function microtime_float(){ list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); }</code>