Thursday, April 16, 2015

The Silver Searcher (ag) vs The Platinum searcher (pt) vs Grep

Browsing the endless sea of internets the other day I came across an article praising The Silver Searcher by Geoff Greer. One thing led to another and after a couple of microseconds I've become aware of The Platinum Searcher existence, and this little gem is claimed to be even more speedy! Awed to no end by their purported lightning-fast performance I decided to give them a shot and see how they stand up to some abuse. I'm using Windows OS in my daily toiling, so all the nasty things that follow were done right there.

My laptop id Lenovo Yoga 2 Pro with the following specs:
  • OS: Windows 8.1 64 bit
  • CPU: 4th Generation Intel Core i3-4030U Processor (1.90GHz 1600 MHz 3MB)
  • Memory: 4.0GB PC3-12800 DDR3L SDRAM 1600 MHz
  • Storage: 128 Gb SSD
First thing I downloaded Linux source code from GitHub (~50000 files, 550 Mb total) to use as a guinea pig. Then for each tool I ran several subsequent searches (to take into account disk cache) against the downloaded Linux codebase looking for a single word "Norway", and here's the average results in a small neat table (and on the right is a snapshot of CPU/Memory/Disk usage):


Tool versionTime in secondsCommand line
pt 1.7.633.3pt /w /stats Norway
GnuWin grep 2.5.46.5timethis grep -r -w Norway *
ag 0.18.18.5ag --literal --stats Norway
ag 0.29.114.4ag --literal --stats Norway

Honestly, looking at the results, I have no idea why Grep gets a lot of frowning upon and why The Platinum Searcher even gets any attention at all, in my case it has shown the worst performance by far being the resource hog at the same time. Life is full of surprises indeed.

It's quite possible I'm just missing something obvious, but then again, it's a perfect real-life use case. I mean, what can be simpler than running a stupid search against a bunch of files?

P.S. Just ran the tests on a Linux machine (Dell PowerEdge 2950/0DT021).
  • OS info: CentOS release 5.7 (Final) x86_64 GNU/Linux version 2.6.18-274.17.1.el5 (gcc version 4.1.2 20080704 (Red Hat 4.1.2-51))
  • CPU: 8 core Intel(R) Xeon(R) X5355 @ 2.66GHz stepping 07
  • Memory: 16 Gb
  • Storage: 750 GB SATAu (7.2K rpm) 
Tool versionTime in secondsCommand line
pt 1.7.660pt -w -stats Norway
Gnu grep 2.5.11.3time grep -r -w Norway *
ag 0.29.12.8ag --literal --stats Norway

And again, The Platinum Searcher is a complete total loser here. I think I'll be sticking to The Silver Searcher for a while (as it seems more flexible than Grep in terms of flexibility when you want to exclude some patterns from your search)...