Ripgrep is faster than {grep, ag, Git grep, ucg, pt, sift}

Ripgrep is a high-performance command-line search tool written in Rust that outperforms popular alternatives like grep and ag. It offers superior speed, robust Unicode support, and respects .gitignore rules by default.
In this article I will introduce a new command line search tool, ripgrep, that combines the usability of The Silver Searcher (an ack clone) with the raw performance of GNU grep. ripgrep is fast, cross platform (with binaries available for Linux, Mac and Windows) and written in Rust.
ripgrep is available on Github.
We will attempt to do the impossible: a fair benchmark comparison between several popular code search tools. Specifically, we will dive into a series of 25 benchmarks that substantiate the following claims:
- For both searching single files and huge directories of files, no other tool obviously stands above
ripgrepin either performance or correctness.ripgrepis the only tool with proper Unicode support that doesn’t make you pay dearly for it. - Tools that search many files at once are generally slower if they use memory maps, not faster.
As someone who has worked on text search in Rust in their free time for the last 2.5 years, and as the author of both ripgrep and the underlying regular expression engine, I will use this opportunity to provide detailed insights into the performance of each code search tool. No benchmark will go unscrutinized!
Target audience: Some familiarity with Unicode, programming and some experience with working on the command line.
Introducing ripgrep
Pitch
Why should you use ripgrep over any other search tool? Well…
- It can replace many use cases served by other search tools because it contains most of their features and is generally faster.
- Like other tools specialized to code search, ripgrep defaults to recursive directory search and won’t search files ignored by your
.gitignorefiles. It also ignores hidden and binary files by default. - ripgrep can search specific types of files. For example,
rg -tpy foolimits your search to Python files andrg -Tjs fooexcludes Javascript files from your search. - ripgrep supports many features found in
grep, such as showing the context of search results, searching multiple patterns, highlighting matches with color and full Unicode support. Unlike GNU grep, ripgrep stays fast while supporting Unicode. - ripgrep has optional support for switching its regex engine to use PCRE2 with
-P. - ripgrep supports searching files in text encodings other than UTF-8, such as UTF-16, latin-1, GBK, EUC-JP, Shift_JIS and more.
- ripgrep supports searching files compressed in a common format (gzip, xz, lzma, bzip2 or lz4) with the
-z/--search-zipflag.
Anti-pitch
I’d like to try to convince you why you shouldn’t use ripgrep.
- You need a portable and ubiquitous tool. The best tool for this job is good old grep.
- There still exists some other feature (or bug) not listed in this README that you rely on that’s in another tool.
- There is a performance edge case where ripgrep doesn’t do well.
- ripgrep isn’t possible to install on your machine.
Installation
The binary name for ripgrep is rg.
- Homebrew:
$ brew install ripgrep - Archlinux:
$ pacman -Syu ripgrep - Rust programmer:
$ cargo install ripgrep
Whirlwind tour
To recursively search the current directory, while respecting all .gitignore files, ignore hidden files and directories and skip binary files:
$ rg foobar
To ignore all ignore files, use -u. To additionally search hidden files and directories, use -uu. To additionally search binary files, use -uuu.
Source: Hacker News










