TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why GNU grep is fast (2010)

209 pointsby goranmoominalmost 3 years ago

9 comments

epagealmost 3 years ago
See also <a href="https:&#x2F;&#x2F;blog.burntsushi.net&#x2F;ripgrep" rel="nofollow">https:&#x2F;&#x2F;blog.burntsushi.net&#x2F;ripgrep</a> which contrasts ripgrep with GNU grep and others (from 2016)
评论 #32214078 未加载
评论 #32214366 未加载
tlbalmost 3 years ago
I&#x27;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&#x27;d avoid and something I&#x27;ll use.
评论 #32216116 未加载
评论 #32216145 未加载
compiler-guyalmost 3 years ago
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.
评论 #32216964 未加载
torstenvlalmost 3 years ago
Related: <a href="https:&#x2F;&#x2F;ridiculousfish.com&#x2F;blog&#x2F;posts&#x2F;old-age-and-treachery.html" rel="nofollow">https:&#x2F;&#x2F;ridiculousfish.com&#x2F;blog&#x2F;posts&#x2F;old-age-and-treachery....</a>
cmarschneralmost 3 years ago
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.
评论 #32223503 未加载
ijidakalmost 3 years ago
Love his summary.<p>&gt; 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...?
xonixalmost 3 years ago
Btw, the GNU awk is also considerably faster (due to bytecode) than awk bundled with BSD &amp; Mac (usually, &quot;one true awk&quot;).
评论 #32214164 未加载
tpoacheralmost 3 years ago
&gt; The key to making programs fast is to make them do practically nothing. ;-)<p>This is going straight to my Anki quotes collection :)
hyperpapealmost 3 years ago
This is a good article, but note that some recent implementations skip the whole Boyer-Moore machinery and don&#x27;t seem to suffer for it <a href="https:&#x2F;&#x2F;lobste.rs&#x2F;s&#x2F;ycydmd&#x2F;why_gnu_grep_is_fast_2010#c_gpim7s" rel="nofollow">https:&#x2F;&#x2F;lobste.rs&#x2F;s&#x2F;ycydmd&#x2F;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:&#x2F;&#x2F;justinblank.com&#x2F;notebooks&#x2F;stringmatching.html" rel="nofollow">https:&#x2F;&#x2F;justinblank.com&#x2F;notebooks&#x2F;stringmatching.html</a>.
评论 #32218699 未加载