Ag. A (somehow even) faster grep

June 25, 2014

The Silver Surfer (creative commons image)

The Silver Surfer (Marvel Comics)

I still remember when I used ack for the first time. It was shortly after I moved to SF, and Brian Rue swore by it. I was as skeptical before trying it as I was blown away after – usually at least 10x faster than grep, and better at ignoring useless files by default.

Adam Morse just told me about Ag (aka “The Silver Searcher”), which somehow embarrasses ack on performance, the same way ack embarrassed grep years ago. It also knows about .gitignore files, and can plug in to vim and TextMate just like ack.

On mac, it’s just…

Install homebrew

ruby -e "$(curl -fsSL"


Install Ag

brew install the_silver_searcher


And you’re off! (other install methods available). I don’t have time for extensive performance tests, but at first glance, ag looks 20 times faster than ack, and 200 times faster than grep

time grep -inrH “testing” . time grep -inrH “emissary” .
real 0m2.875s real 0m2.922s
user 0m2.420s user 0m2.358s
sys 0m0.170s sys 0m0.230s
time ack testing time ack emissary
real 0m0.303s real 0m0.293s
user 0m0.267s user 0m0.265s
sys 0m0.026s sys 0m0.024s
time ag testing time ag emissary
real 0m0.013s real 0m0.014s
user 0m0.007s user 0m0.008s
sys 0m0.009s sys 0m0.009s