I'm using getrusage to get the usertime and systemtime, but sometimes the times returned are negative -->
user time: 1313366639 microseconds
system time: -1547562616 microseconds
I'm not sure I've understood getrusage correctly, so I'm posting my code in hope of getting a few tips on how to avoid the negative numbers... :o)
The output is supposed to be in microseconds, and I read that the output from tv_sec + tv_usec can be both in microseconds and seconds... How do I know which one I get?
struct rusage ru; struct timeval tim; getrusage(RUSAGE_SELF, &ru); tim=ru.ru_utime; double sutime = (double)tim.tv_sec + (double)tim.tv_usec / 1000000.0; printf("SELF:\n"); printf(" user time: %d microseconds\n", sutime); tim=ru.ru_stime; double sstime = (double)tim.tv_sec + (double)tim.tv_usec / 1000000.0; printf(" system time: %d microseconds\n", sstime);