Why GNU grep is fast (2010)
It's probably worth pointing out that OS X is using BSD grep.  You will see a phenomenal difference if you install the gnu grep via homebrew:<p><pre><code>    $ homebrew info grep
    GNU grep, egrep and fgrep
    https://www.gnu.org/software/grep/
    /usr/local/Cellar/grep/3.3 (21 files, 885.3KB) *
      Poured from bottle on 2019-01-03 at 12:23:37
    From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/grep.rb
    ...
</code></pre>
This is a very arbitrary example, but I've got 1.5Gb application log sitting on my machine right now that'll suffice.  I'll even do this in a way that might give a slight performance advantage to BSD, by using gnu grep first:<p><pre><code>    $ time /usr/local/bin/ggrep "foobarbaz" application.log
    
    real 0m1.319s
    user 0m0.948s
    sys 0m0.345s
</code></pre>
vs OSX's grep:<p><pre><code>    $ time /usr/bin/grep "foobarbaz" application.log
    
    real 0m37.225s
    user 0m31.036s
    sys 0m1.286s
</code></pre>
1s vs 37s.  Same file.<p>There's nothing odd about the file, straight boring application logs, and the line starts with the logging level in capital letters.  So I can use a regex that is pinned to the start of the line, about as optimal as you can get:<p>first gnugrep:<p><pre><code>    $ time /usr/local/bin/ggrep -c "^INFO" application.log
    1527786
    
    real 0m0.622s
    user 0m0.323s
    sys 0m0.292s
</code></pre>
then OS X's native bsd grep:<p><pre><code>    $ time /usr/bin/grep -c "^INFO" application.log
    1527786
    
    real 0m3.588s
    user 0m3.206s
    sys 0m0.349s
</code></pre>
BSD grep was significantly better than the prior search, but it is <i>still</i> notably slower than the gnu grep.<p>In my experience, this isn't the most pathological example, but it's close.  Note that this also applies to other tools that leverage grep under the surface, like zgrep etc.<p>I've specifically aliased grep over to ggrep in my shell so that I'm avoiding bsd grep whenever I can:<p><pre><code>    $ alias grep
    alias grep='/usr/local/bin/ggrep'</code></pre>