Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Jul 1999 10:27:26 -0700
From:      John-Mark Gurney <gurney_j@efn.org>
To:        "Daniel C. Sobral" <dcs@newsguy.com>
Cc:        Dag-Erling Smorgrav <des@flood.ping.uio.no>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: replacing grep(1)
Message-ID:  <19990730102726.34286@hydrogen.fircrest.net>
In-Reply-To: <37A1BD1A.59DF842E@newsguy.com>; from Daniel C. Sobral on Fri, Jul 30, 1999 at 11:56:26PM %2B0900
References:  <19990729182229.E24296@mad> <Pine.GSO.4.10.9907291856100.11776-100000@rac9.wam.umd.edu> <19990729164533.36798@hydrogen.fircrest.net> <xzpyafy1d53.fsf@flood.ping.uio.no> <xzpwvvi1czq.fsf@flood.ping.uio.no> <37A1BD1A.59DF842E@newsguy.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Daniel C. Sobral scribbled this message on Jul 30:
> Dag-Erling Smorgrav wrote:
> > 
> > To be precise, I experience a 30% decrease in system time and a 100%
> > increase in user time when I use RE_STARTEND and eliminate the
> > malloc() / memcpy() calls in procfile().
> 
> Could you please test my patch that removes malloc() but bot
> memcpy()? Here it is again, though against an old version:

wierd, I was running your patch, and at first I would get from .69 up
to 1.03 seconds run time, but I can't seem to generate that problem
right now...  w/ your patches I'm getting around .67 to .7 seconds for:
time ./grep THIS /tmp/ports/freegrep/work/grep-0.10/termcap.long  > /dev/null
        0.68 real         0.63 user         0.03 sys
        0.67 real         0.65 user         0.01 sys
        0.67 real         0.63 user         0.03 sys
        0.67 real         0.63 user         0.03 sys
        0.67 real         0.66 user         0.00 sys
        0.67 real         0.64 user         0.02 sys

summary of gprof output:
[3]     50.1    0.02        0.21  108213         procline [3]
[4]     46.7    0.02        0.19  108213         regexec [4]
[7]     28.5    0.13        0.00  108214         mmfgetln [7]
[10]     4.8    0.00        0.02    2393         grep_realloc [10]

with my patch and the exact same command, I get .58 to .59 seconds...
        0.58 real         0.54 user         0.03 sys
        0.58 real         0.53 user         0.04 sys
        0.58 real         0.55 user         0.02 sys
        0.58 real         0.57 user         0.00 sys
        0.59 real         0.55 user         0.02 sys
        0.58 real         0.55 user         0.02 sys

summary of gprof output:
[3]     57.1    0.04        0.19  108213         procline [3]
[4]     48.0    0.02        0.17  108213         regexec [4]
[7]     34.1    0.13        0.00  108214         mmfgetln [7]
[10]     2.0    0.01        0.00       1         _munmap [10]

(I include _munmap because realloc/malloc/free are in the 0.0% on my
patch)

and grep 0.10 w/o patches:
        2.82 real         1.63 user         1.12 sys
        2.79 real         1.53 user         1.20 sys
        2.80 real         1.65 user         1.08 sys
        2.84 real         1.67 user         1.10 sys
        2.82 real         1.67 user         1.08 sys
        2.91 real         1.66 user         1.14 sys

summary of gprof output:
[5]     55.1    1.12        0.00   74985         _madvise [5]
[7]     13.3    0.04        0.23  108213         regexec [7]
[9]      8.4    0.00        0.17  108217         grep_malloc [9]
[13]     6.5    0.13        0.00  108214         mmfgetln [13]

all of the programs were compiled w/ the exact same options... that is
I added -g -pg to the CFLAGS in the Makefile to generate profiling info..

I'm not sure about you, but on my k6/200, the STARTEND is more efficient
than the memcpy/realloc, and to tell you the truth, I can't see why it'd
be more effecient to copy possible multiple kilobytes of data than to just
use indexes instead of modifing a ptr...

right now, I'm trying to think of a way to eliminate the fgetln searching
for end of line... of course this would eliminate some of the simplicity
of design, but we can get a BIG speed increase if we simply don't scan for
the new line unless we NEED to...  and if we do, why not use regexec to
search for us?

-- 
  John-Mark Gurney                              Voice: +1 541 684 8449
  Cu Networking					  P.O. Box 5693, 97405

  "The soul contains in itself the event that shall presently befall it.
  The event is only the actualizing of its thought." -- Ralph Waldo Emerson


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990730102726.34286>