Fast and efficient way to read a space separated file of numbers into an array?

后端 未结 7 738
情话喂你
情话喂你 2021-01-21 03:42

I need a fast and efficient method to read a space separated file with numbers into an array. The files are formatted this way:

4 6
1 2 3 4 5 6
2 5 4 3 21111 101         


        
7条回答
  •  灰色年华
    2021-01-21 04:19

    Unless the machine you're parsing these text files on is limited, files of a few hundred MB should still fit in memory. I'd suggest going with your first approach of reading by line and using split.

    If memory becomes an issue, your second approach of reading in chunks should work fine.

    Basically what I'm saying is just to implement it and measure if performance is a problem.

提交回复
热议问题