Getting getrusage() to measure system time in C
问题 I would like to measure the system time it takes to execute some code. To do this I know I would sandwich said code between two calls to getrusage(), but I get some unexpected results... #include <sys/time.h> #include <sys/resource.h> #include <unistd.h> #include <stdio.h> int main() { struct rusage usage; struct timeval start, end; int i, j, k = 0; getrusage(RUSAGE_SELF, &usage); start = usage.ru_stime; for (i = 0; i < 10000; i++) { /* Double loop for more interesting results. */ for (j = 0;