In this part of code, I am trying to use getrusage to measure time:
getrusage(RUSAGE_SELF, &usage2);
start2 = usage2.ru_stime;
int counter;
for (counter = 0; counter<10000; counter++) {
int j;
int found_elements = 0;
for (j = b; j < c; j++) {
Node *current = NULL;
HASH_FIND_INT(mainhash,&j,current);
if (current) {
found_elements++;
}
}
}
getrusage(RUSAGE_SELF, &usage2);
end2 = usage2.ru_stime;
printf("%.8f", (double)((end2.tv_sec - start2.tv_sec) + (end2.tv_usec - start2.tv_usec)));
with these:
struct rusage usage1, usage2;
struct timeval start1, end1, start2, end2;
But it gives me this on the terminal:
112001.00000000
which i know not true. I need the elapsed time in a format like 5.54676686 (seconds). How can I get it like this properly?