help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Is $(exec external_cmd.sh) always preferred over $(external_


From: Peng Yu
Subject: [Help-bash] Is $(exec external_cmd.sh) always preferred over $(external_cmd.sh)?
Date: Tue, 13 Nov 2018 17:27:50 -0600

Hi,

See the following example, the $() with exec seems to be faster the
one without exec. But there is always fluctuation of my test results.
Is the exec version always preferred? (Besides run time, another
benefit I know is it reduce one process as well.)

$ ./main_performance.sh
tmpfile=$(mktemp -u)
time for((i=0;i<1000;++i))
do
    x=$(./script.sh)
done # > "$tmpfile"

real    0m9.861s
user    0m2.824s
sys    0m5.488s
tmpfile=$(mktemp -u)
time for((i=0;i<1000;++i))
do
    x=$(exec ./script.sh)
done # > "$tmpfile"

real    0m9.525s
user    0m2.781s
sys    0m5.245s

$ cat script.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

echo "$BASHPID"

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]