Trong phiên bản PHP 7+, hàm getrusage có thể được sử dụng. Dưới đây là một đoạn mã mẫu -
Ví dụ
//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"; Lưu ý - Không cần tính toán chênh lệch thời gian nếu một phiên bản php được tạo cho mọi thử nghiệm.
Đầu ra
Điều này sẽ tạo ra kết quả sau -
The process used 1.563896 ms for the computations Spent 0.345628 ms during system calls