Why does Java read a big file faster than C++?

后端 未结 5 2062
太阳男子
太阳男子 2021-01-31 14:19

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

5条回答
  •  无人及你
    2021-01-31 14:33

    I would also try using mmap instead of standard file read/write. This should let your OS handle the reading and writing while your application is only concerned with the data.

    There's no situation where C++ can't be faster than Java, but sometimes it takes a lot of work from very talented people. But I don't think this one should be too hard to beat as it is a straightforward task.

    mmap for Windows is described in File Mapping (MSDN).

提交回复
热议问题