Ask HN: Really long shell command more performant than many short ones?

4 points by nkkollaw ↗ HN
I'm experiencing something that I'm not sure about.

I'm noticing a huge performance gain between concatenating commands with && and running the commands one by one.

None of the commands fail, so I'm not sure why that would be.

Is this normal?

6 comments

[ 3.1 ms ] story [ 23.9 ms ] thread
Could you please provide an example?
I'm on mobile :-/

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

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?
When using remote servers, especially when connecting via HSDPA, I prefer to use https://mosh.org instead of ssh. Although it doesn't impact upon the underlying processing speed, the console terminal becomes more responsive.
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.

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.