EMBED THIS RECORDING:
I made this shell recording to show how to redirect output into
During scriptingexperiences in the past I noticed method #1 is very slow. In this recording I also
experimented a bit with the command 'time', and it turned out to be true.
Anybody got an idea why?
I have no idea what you are talking about. I read your remark above and I became curious. I tried to
reproduce your findings in both Bash and zsh, but I cannot find any speed differences between using
$() and ``. I prefer using $() though, it's way more obvious that `` in scripts.
Coder of Salvation said
Well I just tested it again, but maybe you just pointed out its an problem related to my specific
architecture/linux distro. Check these tests:
$ time BLA=`ls -laR /tmp`
$ time BLA=$(ls -laR /tmp)
Anyways, thanks for pointing out!
You really shouldn't take "ls" to benchmark anything. Once "ls -laR /tmp" has
run, the system is caching the result and thus the second call is faster. It doesn't matter if it's
$() or ``. Execute `` before $() and you'll see.
So you should take a command (or a snippet) which always takes a fixed amount of time, like:
$ time FOO=`for (( N=10000; N--; )); do echo "test" > /dev/null; done`