home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 27.8 glimpse and agrep Chapter 27
Searching Through Files
Next: 27.10 Search RCS Files with rcsgrep
 

27.9 New greps Are Much Faster

grep
Many of the newer, public domain greps such as agrep ( 27.8 ) and GNU egrep , use the much faster Boyer-Moore search algorithm. Both agrep and GNU egrep are on the CD-ROM. [1]

[1] The GNU egrep executable is also installed under the name grep -so don't get confused!

In article 27.6 , we used the runtime program ( 39.4 ) to compare the execution times of fgrep , egrep , and grep . This time we'll use runtime to show the average time needed to search for the string Waldo in a large directory of files. First, let's show the results using agrep :

% 

runtime -10 agrep Waldo *


   ...
AVERAGES:
 0.48u  0.73s 0:01 0+261k 0+0io 0pf+0w

Here's the same output for GNU egrep :

% 

runtime -10 egrep Waldo *


   ...
AVERAGES:
 0.62u  0.62s 0:01 0+242k 0+0io 0pf+0w

Now compare these numbers against those in article 27.6 . For example, here's what we get from the much-maligned everyday grep :

% 

runtime -10 grep Waldo *


   ...
AVERAGES:
 4.13u  0.83s 0:04 0+203k 21+0io 19pf+0w

grep took four clock seconds to search all the files, while both agrep and GNU egrep breezed by in one. So are you a believer yet?

- TOR , LM


Previous: 27.8 glimpse and agrep UNIX Power Tools Next: 27.10 Search RCS Files with rcsgrep
27.8 glimpse and agrep Book Index 27.10 Search RCS Files with rcsgrep

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System