Which is faster?

While reading a standardized file where you know the character-length of each word, which is faster?
fscanf(file,"%s %*s %s",a,b);
or
1
2
3
fscanf(file,"%s",a);
fseek(file,MIDDLE_WORD_LENGTH,SEEK_CUR);
fscanf(file,"%s,b); 


I've implemented the second version in my code and it works just fine, but was suddenly struck with the doubt as to which is actually more efficient, and given how that bit of code runs a few hundred (if not thousand) times each time the program is run, it might be somewhat relevant, if only for a second or two less of delay.
Benchmark it.
While I know what you mean, I know not how to do that.

There's a reason I posted this on the Beginners' Forum. :p
Just run each version a lot of times. 1 million is a popular n for memory, but for disk, I'd say start at 10k. You'll probably want to generate the file programmatically.
The first will be at least as fast as the second for reasonable values of MIDDLE_WORD_LENGTH.
Topic archived. No new replies allowed.