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]

Re: grep


> At 16:30 +0100 11/1/97, Sascha Ziemann wrote:
>
> >(define (grep search-string filename)
> >  (letrec ((grep* (lambda()
> >		    (let ((line (read-line)))
> > ...
> >But the performance is terrible:
> >
> >real    1m34.139s
> >user    1m33.890s
> >sys     0m0.220s
> 
> Wow, a factor of 475 difference.

read-line is abysmally slow.  Read through boot-9.scm and
ioext.c to see exactly why it's so cruel: it is an object
lesson in half-conceived programming.

Try using `%read-line' instead, which calls the desired
port's fgets method for speed.  You should see a marked
improvement in performance.  (Note that I do not claim this
is more elegant than the read-line implementation; only that
it may be crude, but at least it is not also bad.)

love, T.