How to count lines fast?

前端 未结 6 1396
感情败类
感情败类 2020-12-09 15:34

I tried unxutils\' wc -l but it crashed for 1GB files. I tried this C# code

long count = 0;
using (StreamReader r = new StreamReader(f))
{
    st         


        
6条回答
  •  萌比男神i
    2020-12-09 16:01

    Your first approach does look like the optimal solution already. Keep in mind that you're mostly not CPU bound but limited by the HD's read speed, which at 500MB / 4sec = 125MB/s is already quite fast. The only way to get faster than that is via RAID or using SSDs, not so much via a better algorithm.

提交回复
热议问题