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