How can I speed up line by line reading of an ASCII file? (C++)

前端 未结 9 951
夕颜
夕颜 2020-12-30 08:02

Here\'s a bit of code that is a considerable bottleneck after doing some measuring:

//-----------------------------------------------------------------------         


        
9条回答
  •  独厮守ぢ
    2020-12-30 08:35

    If you really want fast, ditch istream and string and create a trivial class Read_Only_Text around const char* & size, then memory map the file and insert into unordered_set with references to the embedded strings. It will mean you needlessly keep the 2mb file even though your number of unique keys may be much less, but it'll be very, very fast to populate. I know this is a pain, but I've done it several times for various tasks and the results are very good.

提交回复
热议问题