single |
The Silver Searcher
A code searching tool similar to ack, with a focus on speed.
What's so great about Ag?
* It is an order of magnitude faster than ack.
* It ignores file patterns from your .gitignore and .hgignore.
* If there are files in your source repo you don't want to search, just
add their patterns to a .ignore file. (*cough* *.min.js *cough*)
* The command name is 33% shorter than ack, and all keys are on home row!
Ag is quite stable now. Most changes are new features, minor bug fixes, or
performance improvements. It's much faster than Ack in benchmarks:
ack test_blah ~/code/ 104.66s user 4.82s system 99% cpu 1:50.03 total
ag test_blah ~/code/ 4.67s user 4.58s system 286% cpu 3.227 total
Ack and Ag found the same results, but Ag was 34x faster (3.2 seconds vs
110 seconds). My ~/code directory is about 8GB. Thanks to git/hg/ignore,
Ag only searched 700MB of that.
How is it so fast?
* Ag uses Pthreads to take advantage of multiple CPU cores and search
files in parallel.
* Files are mmap()ed instead of read into a buffer.
* Literal string searching uses Boyer-Moore strstr.
* Regex searching uses PCRE's JIT compiler (if Ag is built with
PCRE >=8.21).
* Ag calls pcre_study() before executing the same regex on every file.
* Instead of calling fnmatch() on every pattern in your ignore files,
non-regex patterns are loaded into arrays and binary searched.
|