How to detect how many times a certain PHP method is called in a request, and the time and memory consumption of each time?
How to detect how many times a certain method in PHP is called in one request, and the time and memory consumption each time?
<code class="php">function microtime_float () { list( $usec , $sec ) = explode ( " " , microtime ()); return ((float) $usec + (float) $sec ); } function test(){ static $num = 0; $num ++; $memory = memory_get_usage () ; $time_start = microtime_float (); // 操作过程略 usleep ( 100 ); $m = memory_get_usage () -$memory;//内存 $t = microtime_float () -$time_start;//耗时 return [$num,$m,$t]; } test(); test(); print_r(test()); Array ( [0] => 3 [1] => 0 [2] => 0.00016498565673828 )</code>
Maybe you need this
Configure xdebug
+ kcachegrind
and it will be fine.