help-bash
[Top][All Lists]
Advanced

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

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


From: Eduardo Bustamante
Subject: Re: [Help-bash] Is $(exec external_cmd.sh) always preferred over $(external_cmd.sh)?
Date: Tue, 13 Nov 2018 18:16:29 -0800

On Tue, Nov 13, 2018 at 3:28 PM Peng Yu <address@hidden> wrote:
>
> 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
(...)

The difference between the two is 336ms. So that means that you save
336us per iteration.    What kind of script are you implementing that
you're worried about a 336us overhead? is it really worth making your
code less readable just to shave 336us per command substitution?



reply via email to

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