[review,gdb/contrib] Combine sed invocations in words.sh script

Message ID gerrit.1573811593000.Ib08453f3712f32ed02d9f503ee960711ebb9421b@gnutoolchain-gerrit.osci.io
State New, archived
Headers

Commit Message

Simon Marchi (Code Review) Nov. 15, 2019, 9:53 a.m. UTC
  Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/653
......................................................................

[gdb/contrib] Combine sed invocations in words.sh script

Currently running words.sh on all the c source and header files in the repo
takes ~16s in user time:
...
$ time ./gdb/contrib/words.sh \
    $(find -type f -name "*.c" -o -name "*.h") \
    >/dev/null

real    0m7,787s
user    0m16,349s
sys     0m0,367s
...

Rewrite the sed invocations using the -e option from this:
...
   | sed <sedprog1>
   | sed <sedprog2>
...
into this:
...
   | sed \
       -e <sedprog1>
       -e <sedprog2>
...
and reduce user time to ~11s:
...
$ time ./gdb/contrib/words.sh \
    $(find -type f -name "*.c" -o -name "*.h") \
    >/dev/null

real    0m7,243s
user    0m11,220s
sys     0m0,205s
...

gdb/ChangeLog:

2019-11-15  Tom de Vries  <tdevries@suse.de>

	* contrib/words.sh: Combine sed invocations.

Change-Id: Ib08453f3712f32ed02d9f503ee960711ebb9421b
---
M gdb/contrib/words.sh
1 file changed, 6 insertions(+), 5 deletions(-)
  

Comments

Simon Marchi (Code Review) Nov. 22, 2019, 3:27 a.m. UTC | #1
Kevin Buettner has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/653
......................................................................


Patch Set 1: Code-Review+2

LGTM.
  

Patch

diff --git a/gdb/contrib/words.sh b/gdb/contrib/words.sh
index ae38539..8c4fdd0 100755
--- a/gdb/contrib/words.sh
+++ b/gdb/contrib/words.sh
@@ -114,12 +114,13 @@ 
 awk \
     -f "$awkfile" \
     -- "$@" \
-    | sed 's/[%^$~#{}`&=@,. \t\/_()|<>\+\*-]/\n/g' \
-    | sed 's/\[/\n/g' \
-    | sed 's/\]/\n/g' \
-    | sed 's/[0-9][0-9]*/\n/g' \
+    | sed \
+	  -e 's/[%^$~#{}`&=@,. \t\/_()|<>\+\*-]/\n/g' \
+	  -e 's/\[/\n/g' \
+	  -e 's/\]/\n/g' \
+	  -e 's/[0-9][0-9]*/\n/g' \
+	  -e 's/[ \t]*//g' \
     | tr '[:upper:]' '[:lower:]' \
-    | sed 's/[ \t]*//g' \
     | sort \
     | uniq -c \
     | awk "{ if (($minfreq == 0 || $minfreq <= \$1) \