I'm new to this, so this may sound stupid.

    // determine dictionary's size
getrusage(RUSAGE_SELF, &before);
unsigned int n = size();
getrusage(RUSAGE_SELF, &after);

  // calculate time to determine dictionary's size
time_size = calculate(&before, &after);

What is the first getrusage's job? It's supposed update resource usage stats about the current process into the struct rusage. But what is the current process here? Does it only include calling getrusage()? Then how does the 2nd getrusage, get stats about the resource usage stats about size(), the first arg is RUSAGE_SELF?


The current process is speller. The first call to getrusage gathers the statistics at "this point in time", the before. Then program calls size function, then getrusage gathers the statistics about speller at "this point in time", the after. Then it calculates the difference here time_size = calculate(&before, &after);. According to the comment in calculate, it "Returns number of seconds between b and a.". time_size is then reported in the summary here
printf("TIME IN size: %.2f\n", time_size);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .