PHP 버전 7 이상에서는 getrusage 함수를 사용할 수 있습니다. 아래는 샘플 코드 데모입니다 -
예시
//beginning of the script
$exec_start = getrusage();
//other code functionalities
//end of the script
function rutime($ru, $rus, $index) {
return ($ru["ru_$index.tv_sec"]*1000 + intval($ru["ru_$index.tv_usec"]/1000))
- ($rus["ru_$index.tv_sec"]*1000 + intval($rus["ru_$index.tv_usec"]/1000));
}
$ru = getrusage();
echo "The process used " . rutime($ru, $exec_start, "utime") .
" ms for the computations\n";
echo "Spent " . rutime($ru, $exec_start, "stime") .
" ms during system calls\n"; 참고 − 모든 테스트에 대해 php 인스턴스가 생성되면 시차를 계산할 필요가 없습니다.
출력
이것은 다음과 같은 출력을 생성합니다 -
The process used 1.563896 ms for the computations Spent 0.345628 ms during system calls