From: Eric Biggers Date: Sat, 6 May 2017 00:19:33 +0000 (-0700) Subject: common/config: implement set_prog_path() using 'type -P' X-Git-Tag: v2022.05.01~2060 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=904a46958ca0352d6370572723f20a13b5ecf6f5;p=users%2Fhch%2Fxfstests-dev.git common/config: implement set_prog_path() using 'type -P' Bash's 'type -P' builtin is equivalent to 'which', but it's more efficient because it doesn't involve executing an external binary. Because set_prog_path() is executed 60+ times in common/config, which is sourced by common/rc, which in turn is sourced by every test, switching to 'type -P' actually can make a noticeable performance improvement for short-running or skipped tests. For example: Before: # time ./check generic/002 ... Passed all 1 tests real 0m1.365s user 0m0.746s sys 0m0.644s After: # time ./check generic/002 ... Passed all 1 tests real 0m1.026s user 0m0.511s sys 0m0.470s Signed-off-by: Eric Biggers Reviewed-by: Eryu Guan Signed-off-by: Eryu Guan --- diff --git a/common/config b/common/config index b29c0eb0e..8211356c3 100644 --- a/common/config +++ b/common/config @@ -96,12 +96,7 @@ export RECREATE_TEST_DEV=false # $1 = prog to look for set_prog_path() { - p=`which $1 2> /dev/null` - if [ -n "$p" -a -x "$p" ]; then - echo $p - return 0 - fi - return 1 + type -P $1 } # Handle mkfs.btrfs which does (or does not) require -f to overwrite