Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't use C++ stl strings and <code>getline</code> ( or C's fgets), just C style raw pointers and either block read in page-size chunks or mmap the file. </p> <p>Then scan the block at the native word size of your system ( ie either <code>uint32_t</code> or <code>uint64_t</code>) using one of the <a href="http://aggregate.org/MAGIC/#SIMD%20Within%20A%20Register%20(SWAR)%20Operations" rel="noreferrer">magic algorithms</a> 'SIMD Within A Register (SWAR) Operations' for testing the bytes within the word. An example is <a href="http://www.tincancamera.com/examples/wide-finder/src/tbray9.cpp.txt" rel="noreferrer">here</a>; the loop with the <code>0x0a0a0a0a0a0a0a0aLL</code> in it scans for line breaks. ( that code gets to around 5 cycles per input byte matching a regex on each line of a file )</p> <p>If the file is only a few tens or a hundred or so megabytes, and it keeps growing (ie something keeps writing to it), then there's a good likelihood that linux has it cached in memory, so it won't be disk IO limited, but memory bandwidth limited. </p> <p>If the file is only ever being appended to, you could also remember the number of lines and previous length, and start from there.</p> <hr> <p>It has been pointed out that you could use mmap with C++ stl algorithms, and create a functor to pass to std::foreach. I suggested that you shouldn't do it not because you can't do it that way, but there is no gain in writing the extra code to do so. Or you can use boost's mmapped iterator, which handles it all for you; but for the problem the code I linked to was written for this was much, much slower, and the question was about speed not style. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload