Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

'why GNU grep is fast' from the FreeBSD mailing list: http://lists.freebsd.org/pipermail/freebsd-current/2010-Augu...



Which was discussed previously on HN, here: http://news.ycombinator.com/item?id=1626305


> The key to making programs fast is to make them do practically nothing.


I just replicated the test and I can confirm the FreeBSD grep compiled on Darwin is about 30x slower.

    % /usr/local/bin/grep --version         
    /usr/local/bin/grep (GNU grep) 2.14
    <snip>

    % time find . -type f | xargs /usr/local/bin/grep 83ba
    find . -type f  0.01s user 0.06s system 8% cpu 0.870 total
    xargs /usr/local/bin/grep 83ba  0.66s user 0.31s system 95% cpu 1.017 total


    % /usr/bin/grep --version                 
    grep (BSD grep) 2.5.1-FreeBSD

    % time find . -type f | xargs /usr/bin/grep 83ba 
    find . -type f  0.01s user 0.06s system 0% cpu 28.434 total
    xargs /usr/bin/grep 83ba  31.65s user 0.40s system 99% cpu 32.113 total


There was also some discussion about this on one of the Apple mailing lists a few months ago, and it turns out there are major differences in how the two grep implementations on OS X interact with the buffer cache. In particular, empirical evidence suggests 10.6's GNU grep build caches its input, while 10.7+ BSD grep does not.

Incidentally, on OS X, you can commonly get another order of magnitude improvement over even GNU grep with Spotlight's index: use xargs to grep only through files that pass a looser mdfind "pre-screen".




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: