Is StreamReader.Readline() really the fastest method to count lines in a file?

前端 未结 7 1230
逝去的感伤
逝去的感伤 2020-12-30 06:23

While looking around for a while I found quite a few discussions on how to figure out the number of lines in a file.

For example these three:
c# how do I count l

7条回答
  •  一生所求
    2020-12-30 07:01

    The best way to know how to do this fast is to think about the fastest way to do it without using C/C++.

    In assembly there is a CPU level operation that scans memory for a character so in assembly you would do the following

    • Read big part (or all) of the file into memory
    • Execute the SCASB command
    • Repeat as needed

    So, in C# you want the compiler to get as close to that as possible.

提交回复
热议问题