0

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?

1
  • 1
    You could test it, but I imagine there won't be much/any meaningful difference. The bottle neck will be hard drive seek time on a traditional hard drive, and access time on an SSD. These will vary enough that you might not even get an accurate difference in a test if the difference is smaller than variance in seek. 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. Commented Mar 29, 2014 at 3:53

1 Answer 1

2

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.