I have a 2 GB file (iputfile.txt
) in which every line in the file is a word, just like:
apple
red
beautiful
smell
spark
input
I would suspect that the main difference is that java.io.BufferedReader
performs better than the std::ifstream
because it buffers, while the ifsteam does not. The BufferedReader reads large chunks of the file in advance and hands them to your program from RAM when you call readLine()
, while the std::ifstream only reads a few bytes at a time when you prompt it to by calling the >>
-operator.
Sequential access of large amounts of data from the hard drive is usually much faster than accessing many small chunks one at a time.
A fairer comparison would be to compare std::ifstream to the unbuffered java.io.FileReader.