Good bye grep, hello ripgrep

The ultrafast grep replacement

Fernando Villalba
1 min readMay 10, 2019

grep is a great application to search for text within files, it’s also a great application to search within files recursively, and up until now I always thought it was very fast at its job, but then I met ripgrep.

I am not going to show you how to use it (syntax is quite similar to grep) as you can find that out yourself in the page linked above. All I want to show you is a couple of benchmarks, and then you can make up your mind.

First, benchmarks for a single file:

$ cat /dev/random > test
$ ls -lh test
-rw-r--r-- 1 fernandovillalba staff 871M 10 May 22:18 test$ time grep dog test > /dev/nullreal 0m12.649s
user 0m12.438s
sys 0m0.201s
$ time rg dog test > /dev/nullreal 0m0.031s
user 0m0.005s
sys 0m0.007s

That’s 408 times faster than grep searching on a single file!

How about searching recursively in a bunch of directories and files?:

$ ls -R1 repos | wc -l
5129
$ du -sh repos
801M repos
$ time grep -rn repos -e prod > /dev/nullreal 0m25.283s
user 0m23.859s
sys 0m0.631s
$ time rg -rn repos -e prod > /dev/nullreal 0m0.079s
user 0m0.057s
sys 0m0.361s

That’s 326 faster than grep on recursive directories and multiple files!!

I am sorry grep, I loved you, I still do, but it’s time to say goodbye.

--

--