See also <a href="https://blog.burntsushi.net/ripgrep" rel="nofollow">https://blog.burntsushi.net/ripgrep</a> which contrasts ripgrep with GNU grep and others (from 2016)
I'd forgotten to upgrade grep on my latest Macbook. In a large source code repo, looking for a fixed string with no wildcards:<p>osx grep -r:<p><pre><code> real 2m37.786s
user 2m27.034s
sys 0m3.958s
</code></pre>
ggrep -r:<p><pre><code> real 0m12.842s
user 0m5.754s
sys 0m2.825s
</code></pre>
which is the difference between something I'd avoid and something I'll use.
A CS professor of mine said, “You can’t make a computer run faster; you can only make it do less.”<p>That’s not entirely true these days due to things like thermal throttling, but it’s still a great way to think about performance.
grep still runs a regex processor though, which I think by default is a deterministic finite-state machine. I had the impression that even when only fixed strings are used one would still need to use -F to get to full speed. For fixed strings Boyer-Moore is the obvious choice.
Love his summary.<p>> The key to making programs fast is to make them do practically nothing. ;-)<p>It is a great way to think about performance.<p>Is there any way that I can write code such that I avoid this work altogether...?
This is a good article, but note that some recent implementations skip the whole Boyer-Moore machinery and don't seem to suffer for it <a href="https://lobste.rs/s/ycydmd/why_gnu_grep_is_fast_2010#c_gpim7s" rel="nofollow">https://lobste.rs/s/ycydmd/why_gnu_grep_is_fast_2010#c_gpim7...</a>. Minor self-promotion, I grabbed that link from my page on string-matching, <a href="https://justinblank.com/notebooks/stringmatching.html" rel="nofollow">https://justinblank.com/notebooks/stringmatching.html</a>.