> #1 trick: GNU grep is fast because it AVOIDS LOOKING AT EVERY INPUT BYTE.
TFA is incredibly short, and will explain it much better than I can.
> #1 trick: GNU grep is fast because it AVOIDS LOOKING AT EVERY INPUT BYTE.
TFA is incredibly short, and will explain it much better than I can.
This would not help, since the backing storage doesn't provide support for this kind of resolution. It would end up reading in the entire file anyways, unless your input string is on the order of an actual block.
As the other reply mentioned though, it's just that MacBook SSDs are that fast.
Somewhat confusing since it has to look at every byte to find the newlines. They are using a pretty specific definition of "look".
> Moreover, GNU grep AVOIDS BREAKING THE INPUT INTO LINES. Looking for newlines would slow grep down by a factor of several times, because to find the newlines it would have to look at every byte!
I assume the Boyer Moore preprocessor reads a lot of bytes also.
Not disputing it's more efficient, but there's no magic. It avoids reading some bytes when and if it can.
It can whenever you don't ask for line numbers, can't it?
> It probably looks for newlines after a match is found
Probably, yeah. Counting number of newlines in a range, without caring just where they fall, can probably be pretty darned fast with vector instructions. Idk if that's worth the additional pass, though.
Another way of looking at is just considering the ^ another character (plus one-off special handling for start of file).