If it's unix, for max perf. I'd seek to successive (4096 byte) buffered IO page boundaries per outer iteration, transfer the lines contained to an array, process those in an inner iteration and carry over the last incomplete line (if no \n) to the next IO page iteration.