You can use the system time command to check this information from the outside:
/usr/bin/time PHP .php
which will print something like:
0.03user 0.00system 0:03.04elapsed 0%CPU (0avgtext+0avgdata 32752maxresident)k 0inputs+0outputs (0major+2234minor)pagefaults 0swaps
Of course, don't forget that getrusage () information is the processor time, and microtime () is the wall clock. The program can run for 10 minutes according to the clock on the wall, but internally it can only use a few seconds of processor time. They then compete for CPU time with all background programs running on the system, resource conflicts, and regular households.
There are too many factors with which you can get the exact time for such short periods. Performing three runs of the while(microtime()) version of your loop, I got the following timings:
user: 0.98, 0.09, 0.90 sys: 0.12, 0.05, 0.94
Obviously, pretty variance. Even simple <? print_r(getrusage()) ?> <? print_r(getrusage()) ?> has utime / stimes ranging from 0 to 0.03.
Try using your loops for longer periods of time and do something in them to increase processor utilization. Your numbers are too small right now to measure accurately.
source share