Last active
March 1, 2019 08:06
-
-
Save nurullahisik/1bc76592904b3db44f522352b1873fc2 to your computer and use it in GitHub Desktop.
For this, we are going to utilize the getrusage() function. Keep in mind that this is not available on Windows platforms.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
print_r(getrusage()); | |
/* prints | |
Array | |
( | |
[ru_oublock] => 0 | |
[ru_inblock] => 0 | |
[ru_msgsnd] => 2 | |
[ru_msgrcv] => 3 | |
[ru_maxrss] => 12692 | |
[ru_ixrss] => 764 | |
[ru_idrss] => 3864 | |
[ru_minflt] => 94 | |
[ru_majflt] => 0 | |
[ru_nsignals] => 1 | |
[ru_nvcsw] => 67 | |
[ru_nivcsw] => 4 | |
[ru_nswap] => 0 | |
[ru_utime.tv_usec] => 0 | |
[ru_utime.tv_sec] => 0 | |
[ru_stime.tv_usec] => 6269 | |
[ru_stime.tv_sec] => 0 | |
) | |
*/ | |
/* | |
ru_oublock: block output operations | |
ru_inblock: block input operations | |
ru_msgsnd: messages sent | |
ru_msgrcv: messages received | |
ru_maxrss: maximum resident set size | |
ru_ixrss: integral shared memory size | |
ru_idrss: integral unshared data size | |
ru_minflt: page reclaims | |
ru_majflt: page faults | |
ru_nsignals: signals received | |
ru_nvcsw: voluntary context switches | |
ru_nivcsw: involuntary context switches | |
ru_nswap: swaps | |
ru_utime.tv_usec: user time used (microseconds) | |
ru_utime.tv_sec: user time used (seconds) | |
ru_stime.tv_usec: system time used (microseconds) | |
ru_stime.tv_sec: system time used (seconds) | |
*/ | |
// sleep for 3 seconds (non-busy) | |
sleep(3); | |
$data = getrusage(); | |
echo "User time: ". | |
($data['ru_utime.tv_sec'] + | |
$data['ru_utime.tv_usec'] / 1000000); | |
echo "System time: ". | |
($data['ru_stime.tv_sec'] + | |
$data['ru_stime.tv_usec'] / 1000000); | |
/* prints | |
User time: 0.011552 | |
System time: 0 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment