ack 2.02 はバグありで遅いから ag がお勧め

隣のエンジニアが ackを捨てて、より高速なag(The Silver Searcher)に切り替えたを読んで ag に切り替えた。

ので私も ag に切り替えた。

が、先月 4/23 にソースコード検索に特化したコマンドラインツール「ack 2.02」という記事を読み、ack がもしかして ag に対抗して高速化したのか?と妄想した。

が、遅かった。引き続き ag を使いましょう。

しかも ack 2.02 はバグがあって異常に遅いです。

http://cpansearch.perl.org/src/PETDANCE/ack-2.04/Changes

ack 2.02 was much slower than ack 1.96, up to 8x slower in some cases.
These slowdowns have been mostly eliminated, and in some cases ack 2.04
is now faster than 1.96.

ack 2.04 で修正されたけど、2.02 は 1.96 の 8 倍以上遅い場合があったそうです。

で、ack 2.04 と ag 0.14 のベンチマーク結果。

# ファイル数
$ find ~/work/ -type f | wc -l
55430

# ディレクトリ容量
$ du -sh ~/work/
1.8G .

# grep の実行時間
$  time grep -r hello work |wc -l
1845
grep -r hello work  0.72s user 0.71s system 1% cpu 1:51.05 total
wc -l  0.00s user 0.01s system 0% cpu 1:51.04 total

# ack の実行時間
$ time ack   hello work |wc -l
1769
ack hello work  30.75s user 3.82s system 30% cpu 1:52.02 total
wc -l  0.00s user 0.00s system 0% cpu 1:52.01 total

# ag の実行時間
$ time ag hello work |wc -l
1720
ag hello work  0.71s user 1.67s system 3% cpu 1:10.76 total
wc -l  0.00s user 0.00s system 0% cpu 1:10.75 total

それぞれ 5 回実行して 2 番目に速かった値です。

ack と grep の実行時間が誤差レベル。