分享 比 ack 更快更好用的东东:the silver searcher

lgn21st · 2013年02月17日 · 最后由 franklinyu 回复于 2016年03月30日 · 23560 次阅读

比 ack 更快,而且还可以跟 vim,textmate,emacs 集成,推荐之。 https://github.com/ggreer/the_silver_searcher

The Silver Searcher

An attempt to make something better than ack (which itself is better than grep).

What's so great about Ag?

  • It searches code about 3–5× 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 .agignore file. *cough* extern *cough*
  • The command name is 33% shorter than ack!

How is it so fast?

  • Searching for literals (no regex) uses Boyer-Moore-Horspool strstr.
  • Files are mmap()ed instead of read into a buffer.
  • If you're building with PCRE 8.21 or greater, regex searches use the JIT compiler.
  • Ag calls pcre_study() before executing the regex on a jillion files.
  • Instead of calling fnmatch() on every pattern in your ignore files, non-regex patterns are loaded into an array and binary searched.
  • Ag uses Pthreads to take advantage of multiple CPU cores and search files in parallel.

I've written several blog posts showing how I've improved performance. These include how I added pthreads, wrote my own scandir(), benchmarked every revision to find performance regressions, and profiled with gprof and Valgrind.

Installation

OS X:

brew install the_silver_searcher

多么好的一个 pick.... :)

#1 楼 @poshboytl 以前 pick 都是推荐 gem 啥的,感觉不给力阿,以后 pick 要专注于推荐人文方面的东西,技术方面的直接贴到论坛里面好了。

貌似不错啊 这个挺有意思 The command name is 33% shorter than ack! 哈哈

最新的 janus 已经支持,更新后删掉 ack 默认就调用 the silver searcher 了。感觉确实快许多

不错,唯快不破!

不错,如果能有 ack --types 的支持就更好了

就是名字太长,不太好记,过段时间就忘了

默认居然是 emerge 不是 apt,好个性

ack blahblahblah ~/code 6.59s user 1.94s system 99% cpu 8.547 total ag blahblahblah ~/code 1.39s user 1.81s system 229% cpu 1.396 total

这个 CPU 利用率也挺高的。看来 ag 比 ack 要更加勤奋一点。

赞啊,试试看,Ack 经常觉得不是很爽

试用了一下,不过 the_silver_searcher 不支持 --nojs 这样的选项,略不爽。

ack 支持几乎所有 filetypes. ack --help-types

飞一般的感觉,Enter 按下马上就出结果了。

报告~ 已经用 ag 替换掉了 grep ;)

推存一个比 ag 还快的东东,beagrep(我是作者)。

https://github.com/baohaojun/beagrep

#15 楼 @baohaojun 牛,不过 ag 表现已经很让我惊艳了,刚刚测试了下:

~ $ brew search beagrep
No formula found for "beagrep". Searching open pull requests...

目前还无法通过 brew 安装,考虑把 beagrep 放到 homebrew 中么?这样的话说不定会帮助推广。

Ag > Ack > Grep Vim 下面我用了长时间的 grep,真是伤不起啊。

#15 楼 @baohaojun 看了下 configure.in 作为一个命令行工具,依赖有点重啊。mono 还能理解,怎么还依赖 GTK ?

只见过 grep 的 Java 程序猿表示很悲惨。学习了……

#16 楼 @lgn21st 啊,我还没有在 Mac 下跑过,买来 Macbook air 之后用不习惯,大部分时间还是在 Linux 下

#18 楼 @doitian 没错,您看得挺仔细。beagrep 源于 beagle 项⽬,这个项⽬已经不再继续开发了,由于缺乏维护所以也被从 debian/ubuntu 里拿下了。之前的 beagle 是一个桌面搜索工具,目前应该已经被 tracker 取代。我已经尽量把很多依赖剥掉,但还是不够彻底。不过应该不影响使用:-)

有空的话我还会继续做减法:-)

这个挺有意思 刚刚测试了下:grep 快啊。

居然是 grep > ag > ack

#22 楼 @reboot 我猜你測的樣本不是源碼(而是通用文本),或者你的 SSD 比較好?如果 IO 效率高,grepag畢竟是 C,還是會ack(Perl)快的。在機械硬盤的情況下,IO 是瓶頸,agack會篩選文件,就能省下很多時間。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号