This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

grep



The real grep is hyperoptimized.  Compare GNU grep with the equivalent
trivial Perl script, and I'll wager GNU will still win pretty well.

Here's pgrep:

#!/usr/local/bin/perl

while (<>) {
  print if (/Subject: /);
}

Here are some numbers (I've omitted a few prompts for clarity):

totoro:mail$ ls -l INBOX
-rw-rw-rw-   1 jimb     users     4310955 Nov  3 23:59 INBOX
totoro:mail$ grep 'Subject: ' < INBOX | wc -l    
   1517
totoro:mail$ time pgrep < INBOX > /dev/null
       12.5 real         9.2 user         2.5 sys  
       11.9 real         9.2 user         2.4 sys  
       11.9 real         9.2 user         2.4 sys  
totoro:mail$ time grep 'Subject: ' < INBOX > /dev/null
        3.1 real         0.2 user         2.1 sys  
        3.0 real         0.2 user         2.1 sys  
        3.0 real         0.2 user         2.1 sys  
totoro:mail$ 

Now, this doesn't excuse Guile's performance.  The current Guile I/O
facilites are known not to be the fastest, and its string management
isn't great.  Those can be fixed.  I also think Perl can pull nice
allocation tricks for $_ that Guile would be hard-pressed to follow.

In short, some of this will be fixed, but you'll never beat grep.