getline while reading a file vs reading whole file and then splitting based on newline character

后端 未结 6 1429
孤街浪徒
孤街浪徒 2020-12-16 17:09

I want to process each line of a file on a hard-disk now. Is it better to load a file as a whole and then split on basis of newline character (using boost), or is it better

6条回答
  •  余生分开走
    2020-12-16 17:40

    Its better to fetch the all data if it can be accommodated in memory because whenever you request the I/O your programmme looses the processing and put in a wait Q.

    enter image description here

    However if the file size is big then it's better to read as much data at a time which is required in processing. Because bigger read operation will take much time to complete then the small ones. cpu process switching time is much smaller then this entire file read time.

提交回复
热议问题