Actually this is not particular to C, but assume using C first, if I have a program that read from stdin
, and a program read from a file using fopen
, how to compare their efficiency in processing file?
What would be the overheads on both cases?
If you mean to compare reading from a file that's received as stdin
(e.g. ./prog < file
) versus opened within the program via fopen
, there should be no difference in efficiency whatsoever.
If you mean to compare reading from a pipe or terminal or other non-regular-file received as stdin
versus opening regular file with fopen
, you're comparing apples and oranges and I don't think the question makes sense without further details.
stdin
may have slightly more overhead, as it is meant for user entry, but if you are piping a file into to, I doubt it is enough to make a significant difference.