In case you haven't figured it out, the speller program collects computer time usage data on each of the four functions of load(), check(), size() and unload(), using the getrusage() function. In simple terms, it gets timestamps before and after each of the 4 target functions and calculates time used.
The calls to
getrusage(...) are strictly to calculate the computing time expended between the &before and &after calls. The activities of the functions between the two calls have no direct bearing on the data generated by getrusage().
For the load() function, it's a single call to determine total processing time used by the load() function, so getrusage() only needs to be called once before and once after. The data in those two structures is then compared to get the processing time.
For check, it's a little different. This is in a for loop because the speller code itself has to get a word from the text file under test and check that it's a valid word to be submitted to the check() function (there are a number that are not valid). After all that other stuff is done, the check() function will be called for that word. It's important that all that housekeeping is done outside of the timing mechanism of getrusage() so that it doesn't impact the collection of timing data.
On each pass through the for loop, only one word is submitted to the check() function. Because of this, the code was set up to accumulate the time data. You are correct that each pass overwrites the data in &before and &after. This is not a problem though, because the elapsed time data is calculated and a running total is kept in
time_check, so the data is not lost. The two var structures are just being reused on each pass.
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)