
Ask HN: Really long shell command more performant than many short ones? - nkkollaw
I&#x27;m experiencing something that I&#x27;m not sure about.<p>I&#x27;m noticing a huge performance gain between concatenating commands with &amp;&amp; and running the commands one by one.<p>None of the commands fail, so I&#x27;m not sure why that would be.<p>Is this normal?
======
savethefuture
Could it be network lag from a remote server? And when doing single commands
the prompt doesn't appear right away, so it seems slower?

~~~
CyberFonic
When using remote servers, especially when connecting via HSDPA, I prefer to
use [https://mosh.org](https://mosh.org) instead of ssh. Although it doesn't
impact upon the underlying processing speed, the console terminal becomes more
responsive.

------
CyberFonic
Which shell, which OS? Is it within a script or when entering from the
console? Have you actually timed your tests?

My first reaction to your question was that each command is executed as a
separate process and depending on what you are doing, e.g. piping outputs to
inputs, using temporary files, other operations could create lots of variances
between one run and the next.

------
tedmiston
Perhaps the CPU scheduler is working to your disadvantage with multiple
commands running separately.

Another thought is maybe data is in a faster state of cache in the combined
command, but in separate commands is getting dumped to something slower.

------
anonymous_iam
Could you please provide an example?

~~~
nkkollaw
I'm on mobile :-/

I'll post again once I'm back at the PC.

