Peng Yu
2018-12-07 16:45:05 UTC
Hi,
$() is quite expensive.
Would it make sense to add a variable like BASH_RETURN so that
functions can optionally write results to it for later commands to
retrieve?
Due to the especially of the proposed BASH_RETURN, I think that it
probably should not be a regular global variable. I'd expect that
there should some specific features (although I am not quite clear
what it should be) associated with it to make it really useful.
$ ./main.sh
time for ((i=0;i<1000;++i))
do
x=$(f)
done
1.445
time for ((i=0;i<1000;++i))
do
g
done
0.024
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
function f {
echo 42
}
function g {
x=42
}
TIMEFORMAT=%R
set -v
time for ((i=0;i<1000;++i))
do
x=$(f)
done
time for ((i=0;i<1000;++i))
do
g
done
$() is quite expensive.
Would it make sense to add a variable like BASH_RETURN so that
functions can optionally write results to it for later commands to
retrieve?
Due to the especially of the proposed BASH_RETURN, I think that it
probably should not be a regular global variable. I'd expect that
there should some specific features (although I am not quite clear
what it should be) associated with it to make it really useful.
$ ./main.sh
time for ((i=0;i<1000;++i))
do
x=$(f)
done
1.445
time for ((i=0;i<1000;++i))
do
g
done
0.024
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
function f {
echo 42
}
function g {
x=42
}
TIMEFORMAT=%R
set -v
time for ((i=0;i<1000;++i))
do
x=$(f)
done
time for ((i=0;i<1000;++i))
do
g
done
--
Regards,
Peng
Regards,
Peng