An ack clone written in Node.js. The focus here is on speed and performance, rather than trying to 100% mimic all the functionality of ack.
There were two goals set out:
- Be faster than ack
- Return matches in order
I've benchmarked in numerous places where and why code is written as it is, as well as possible areas of improvement. It's mostly asynchronous, though due to the requirement of returning items in order, performs a mergesort at the end of all the results obtained.
As long as it's faster than ack, I'm pleased.
A lot of the functionality is modeled around ag. In fact, you can provide an .nakignore file to define patterns to ignore. .nakignore files in the directory you're searching under are automatically included as ignore rules, but you can choose to specify an additional file with -a
.
After reading Felix's Faster than C notes, I became inspired to just write a fast ack clone, in Node.js.
Previously, TJ had written an ack clone in Node, but his code was not very performant. At least, it was slower than ack.
I benchmarked and rewrote and learned a lot. While nak does not support everything ack does, it does nearly everything ag does, and, at least, 100% supports everything we need for Cloud9.
You like numbers? Me too. They're fun.
Here's the average time for grabbing the filelist in cloud9infra five times (about 33,761 files). The commands do the exact same thing (get hidden files, e.t.c.) and exclude the same nonsense directories ( .git, .c9revisions, sm
backups, e.t.c.). :
ag |
nak |
ack |
find |
---|---|---|---|
0m0.184s | 0m0.940s | 0m1.103s | 0m1.093s |
Here are benchmarks for finding the phrase "va" in cloud9infra:
ag |
nak |
ack |
grep |
---|---|---|---|
0m2.599s | 0m20.021s | 0m29.876s | 0m20.891s |
All tests (and comparissons to ag) can be found in tests, and uses [mocha](http://visionmedia.github.com/mocha/)
to run. Just call mocha filelist
or mocha search
.
For a discussion on this tool versus ag, find, and grep, see this pull request into Cloud9.