Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Aug 2010 08:52:15 -0500 (CDT)
From:      "Sean C. Farley" <scf@FreeBSD.org>
To:        =?ISO-8859-15?Q?Dag-Erling_Sm=F8rgrav?= <des@des.no>
Cc:        Gabor Kovesdan <gabor@FreeBSD.org>, current@FreeBSD.org
Subject:   Re: Official request: Please make GNU grep the default
Message-ID:  <alpine.BSF.2.00.1008160813280.21804@thor.farley.org>
In-Reply-To: <86y6c7bse5.fsf@ds4.des.no>
References:  <4C6505A4.9060203@FreeBSD.org> <4C650B75.3020800@FreeBSD.org> <alpine.BSF.2.00.1008131034440.35204@thor.farley.org> <86y6c7bse5.fsf@ds4.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--56599777-1799541866-1281964549=:21804
Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8BIT
Content-ID: <alpine.BSF.2.00.1008160821461.21804@thor.farley.org>

On Sun, 15 Aug 2010, Dag-Erling Smørgrav wrote:

> "Sean C. Farley" <scf@FreeBSD.org> writes:
>> This should trim some time off BSD grep.
>
> Did you actually test your patch?  It makes absolutely no measurable 
> difference.

Yes, I saw a reduction, using the first test script Doug provided, from 
36 to 27 seconds.  I only sent the patch after profiling confirmed a 
reduction.  The script ran non-profiled grep 100 times.  "Trim" did not 
imply it would reduce the time from 36 to 2 seconds.

Here are profiles of one execution of bsdgrep using the parameters from 
the script.

Non-patched grep (cumulative time 4.17 seconds):
   %   cumulative   self              self     total
  time   seconds   seconds    calls  ms/call  ms/call  name
  79.5       3.32     3.32        0  100.00%           _mcount [1]
   7.9       3.65     0.33        0  100.00%           .mcount (106)
   4.5       3.83     0.19 21971711     0.00     0.00  fgetc [7]
   3.5       3.98     0.15 21993762     0.00     0.00  grep_feof [8]
   2.5       4.09     0.10 21971711     0.00     0.00  grep_fgetc [6]
   1.5       4.15     0.06    22051     0.00     0.02  grep_fgetln [5]
   0.5       4.17     0.02     1352     0.02     0.02  read [9]
   0.0       4.17     0.00       67     0.02     0.02  memset [14]
   0.0       4.17     0.00       61     0.01     0.01  arena_run_split [17]
   0.0       4.17     0.00        1     0.50   522.57  procfile [4]
...

Patched grep (cumulative time 2.82 seconds):
   %   cumulative   self              self     total
  time   seconds   seconds    calls  ms/call  ms/call  name
  77.4       2.19     2.19        0  100.00%           _mcount [1]
   8.4       2.42     0.24        0  100.00%           .mcount (109)
   6.1       2.60     0.17 21971711     0.00     0.00  grep_fgetc [6]
   4.9       2.74     0.14 21993762     0.00     0.00  grep_feof [7]
   2.7       2.81     0.08    22051     0.00     0.02  grep_fgetln [5]
   0.3       2.82     0.01     1352     0.01     0.01  _read [10]
   0.1       2.82     0.00       67     0.03     0.03  memset [13]
   0.1       2.82     0.00       10     0.15     0.15  free [16]
   0.0       2.82     0.00        1     1.00   398.11  procfile [4]
...

getc_unlocked() is merely a macro around __sgetr() as opposed to calling 
into getc().  My patch was to show it could be reduced by removing some 
of stdio's overhead (one function call and unneeded locking).  I did not 
have time to do a complete removal of stdio as I was unsure of any 
dependencies this version of bsdgrep had on stdio.

For some reason, I thought there was mention of making bsdgrep into an 
application and library.  If threading became involved, losing fgetc() 
would help more.  Without threading, the test for locking would still be 
performed in getc().

Sean
-- 
scf@FreeBSD.org
--56599777-1799541866-1281964549=:21804--



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