diff options
author | P. J. McDermott <pjm@nac.net> | 2013-05-09 11:29:28 (EDT) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2013-05-09 11:42:59 (EDT) |
commit | c1f7cccfdc8d07873804c8128d58721f002bacb0 (patch) | |
tree | 299e94b0dfd89864c57effd79aae778dfcbc3255 | |
parent | bf813b61f45499db4dce4848ab6f67e4b013fbcd (diff) |
Makefile.in: Replace old sed cmds with basename.
The result is the same, and basename is a bit faster than sed is.
A quick and dirty benchmark:
printf 'printf and sed:\n'
i=0
while [ ${i} -lt 3 ]; do
time -p sh >/dev/null <<-EOF
i=0
while [ \${i} -lt 1000 ]; do
printf '%s' 'foo/bar' | sed 's|^.*/||'
i=\$((\$i + 1))
done
EOF
i=$(($i + 1))
done
printf '\nbasename:\n'
i=0
while [ ${i} -lt 3 ]; do
time -p sh >/dev/null <<-EOF
i=0
while [ \${i} -lt 1000 ]; do
basename 'foo/bar'
i=\$((\$i + 1))
done
EOF
i=$(($i + 1))
done
And the unsurprising results:
printf and sed:
real 1.17
user 0.02
sys 0.17
real 1.18
user 0.01
sys 0.18
real 1.17
user 0.02
sys 0.16
basename:
real 0.74
user 0.02
sys 0.08
real 0.74
user 0.02
sys 0.08
real 0.72
user 0.04
sys 0.06
basename is about 37% – 38% faster.
-rw-r--r-- | Makefile.in | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Makefile.in b/Makefile.in index 4ef1a45..b13f688 100644 --- a/Makefile.in +++ b/Makefile.in @@ -158,7 +158,7 @@ install-bin: @mkdir -p '$(DESTDIR)/$(bindir)' @for f in $(bin); do \ printf ' INSTALL %s\n' "$${f}"; \ - ff="$$(printf '%s' "$${f}" | sed 's|^.*/||')"; \ + ff="$$(basename "$${f}")"; \ cp "$${f}" "$(DESTDIR)/$(bindir)/$${ff}"; \ chmod 755 "$(DESTDIR)/$(bindir)/$${ff}"; \ done @@ -166,7 +166,7 @@ install-pkglib: @mkdir -p '$(DESTDIR)/$(pkglibdir)' @for f in $(pkglib); do \ printf ' INSTALL %s\n' "$${f}"; \ - ff="$$(printf '%s' "$${f}" | sed 's|^.*/||')"; \ + ff="$$(basename "$${f}")"; \ cp "$${f}" "$(DESTDIR)/$(pkglibdir)/$${ff}"; \ chmod 644 "$(DESTDIR)/$(pkglibdir)/$${ff}"; \ done @@ -174,7 +174,7 @@ install-pkglibbuildsystem: @mkdir -p '$(DESTDIR)/$(pkglibbuildsystemdir)' @for f in $(pkglibbuildsystem); do \ printf ' INSTALL %s\n' "$${f}"; \ - ff="$$(printf '%s' "$${f}" | sed 's|^.*/||')"; \ + ff="$$(basename "$${f}")"; \ cp "$${f}" "$(DESTDIR)/$(pkglibbuildsystemdir)/$${ff}"; \ chmod 644 "$(DESTDIR)/$(pkglibbuildsystemdir)/$${ff}"; \ done @@ -183,7 +183,7 @@ install-man1: @mkdir -p '$(DESTDIR)/$(man1dir)' @for f in $(man1); do \ printf ' INSTALL %s\n' "$${f}"; \ - ff="$$(printf '%s' "$${f}" | sed 's|^.*/||')"; \ + ff="$$(basename "$${f}")"; \ cp "$${f}" "$(DESTDIR)/$(man1dir)/$${ff}"; \ chmod 644 "$(DESTDIR)/$(man1dir)/$${ff}"; \ done @@ -203,26 +203,26 @@ uninstall-exec: uninstall-bin uninstall-pkglib uninstall-pkglibbuildsystem uninstall-bin: @for f in $(bin); do \ printf ' RM %s\n' "$${f}"; \ - ff="$$(printf '%s' "$${f}" | sed 's|^.*/||')"; \ + ff="$$(basename "$${f}")"; \ rm -f "$(DESTDIR)/$(bindir)/$${ff}"; \ done uninstall-pkglib: @for f in $(pkglib); do \ printf ' RM %s\n' "$${f}"; \ - ff="$$(printf '%s' "$${f}" | sed 's|^.*/||')"; \ + ff="$$(basename "$${f}")"; \ rm -f "$(DESTDIR)/$(pkglibdir)/$${ff}"; \ done uninstall-pkglibbuildsystem: @for f in $(pkglibbuildsystem); do \ printf ' RM %s\n' "$${f}"; \ - ff="$$(printf '%s' "$${f}" | sed 's|^.*/||')"; \ + ff="$$(basename "$${f}")"; \ rm -f "$(DESTDIR)/$(pkglibbuildsystemdir)/$${ff}"; \ done uninstall-data: uninstall-man1 uninstall-locale uninstall-man1: @for f in $(man1); do \ printf ' RM %s\n' "$${f}"; \ - ff="$$(printf '%s' "$${f}" | sed 's|^.*/||')"; \ + ff="$$(basename "$${f}")"; \ rm -f "$(DESTDIR)/$(man1dir)/$${ff}"; \ done uninstall-locale: |