PHP 7+ संस्करण में, getrusage फ़ंक्शन का उपयोग किया जा सकता है। नीचे एक नमूना कोड प्रदर्शन है:
उदाहरण
// स्क्रिप्ट की शुरुआत
$exec_start = getrusage();
// अन्य कोड कार्यक्षमताएं
// स्क्रिप्ट का अंत
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