On Sun, 15 Aug 2010, Dag-Erling Smørgrav wrote:
"Sean C. Farley" <s...@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
--
s...@freebsd.org
_______________________________________________
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"