I\'ve written a program that reads an whole file via fgetc
:
while ((c = fgetc(f)) != EOF) { ... }
But the program is too slow. Whe
With fgetc you not only get more function calls (each one has its overhead), but fgetc may also takes locks in multi-threaded application (this is mandated for instance by POSIX).
You live close to a store. You need to get 100 cans of soup. Which is more efficient, 100 trips to the store getting 1 can each time or 1 trip to the store getting 100 cans? Obviously the 1 trip because each trip has overhead that takes time.
In the case of fgetc there are various kinds of overhead.
These things can be done once for all the soup, or once for each can. Individually each bit of overhead is small but when repeated many times, the sum becomes significant.