比 ack-grep 更快更好用的东东:the silver searcher

比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 gprofand Valgrind.

Building from source

  1. Install dependencies (Automake, pkg-config, PCRE, LZMA):

    • Ubuntu: apt-get install -y automake pkg-config libpcre3-dev zlib1g-dev liblzma-dev
    • CentOS:

       yum -y groupinstall "Development Tools"
        yum -y install pcre-devel xz-devel 
    • OS X:

      • Install homebrew, then brew install automake pkg-config pcre
      • Or install macports, then port install automake pkgconfig pcre
    • Windows: It's complicated. See this wiki page.

  2. Run the build script (which just runs aclocal, automake, etc):

    • ./build.sh
  3. Make install:

    • sudo make instal

你可能感兴趣的:(比 ack-grep 更快更好用的东东:the silver searcher)