0

In case of millions of line in a file, which API would be faster and can be parallelised?

File.ReadLines or Streamreader.Readline?

11
  • 7
    They do the same thing. File.ReadLines uses a StreamReader internally Commented Jun 10, 2020 at 12:15
  • So why we have two apis for same thing? Commented Jun 10, 2020 at 12:16
  • 4
    it's another level of abstraction Commented Jun 10, 2020 at 12:17
  • 2
    StreamReader is more powerful, but more verbose to use if you just want to iterate over all lines in a file. File.ReadLines just iterates over all lines in a file and none of the other stuff, but can do it in 1 line of code Commented Jun 10, 2020 at 12:20
  • 2
    Then you need task-parallelism, not only data-parallelism. One thread for reading data from the filesystem at maximum speed and storing them somewhere in memory, and multiple threads processing these data. Search about the producer-consumer pattern, and the BlockingCollection class or the TPL Dataflow library. Commented Jun 10, 2020 at 12:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.