"A simple rule in computers is to make something run faster, have it do less work. I remember reading about how grep works quickly. Instead of splitting a file by lines and then searching for the string, it searches for the string, then finds the newlines on either side. Thus, if a file has no matches, it won't ever have to do the work for line splitting. Done the naive way, it would always split by line even if there was no match. Do less work."
Good observation, but I doubt if that's remotely even the reason why grep works quickly.
I have seen those and those were what I was implicitly referring to. And if you did read them,"- Don't look for newlines in the input until after you've found a match." is just one of them but not the major contributor for speed. It's Boyer-Moore.
> 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!
(italics added, but uppercase original!) On my reading this sounds quite huge; I seem to understand the gist is that it's still a significant gain after Boyer-Moore. But, whatever.
"A simple rule in computers is to make something run faster, have it do less work. I remember reading about how grep works quickly. Instead of splitting a file by lines and then searching for the string, it searches for the string, then finds the newlines on either side. Thus, if a file has no matches, it won't ever have to do the work for line splitting. Done the naive way, it would always split by line even if there was no match. Do less work."
Good observation, but I doubt if that's remotely even the reason why grep works quickly.