Полезная информация

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

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 *
 0.48u  0.73s 0:01 0+261k 0+0io 0pf+0w

Here's the same output for GNU egrep:

% runtime -10 egrep Waldo *
 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 *
 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?


Previous: 27.8 glimpse and agrep UNIX Power ToolsNext: 27.10 Search RCS Files with rcsgrep
27.8 glimpse and agrep Book Index27.10 Search RCS Files with rcsgrep

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