Re: The difference between `X=x f | cat` and `{ X=x; f; } | cat`
From:
Kerin Millar
Subject:
Re: The difference between `X=x f | cat` and `{ X=x; f; } | cat`
Date:
Thu, 19 Jan 2023 17:35:47 +0000
On Thu, 19 Jan 2023 10:53:42 -0500
Greg Wooledge <greg@wooledge.org> wrote:
> On Thu, Jan 19, 2023 at 03:49:06PM +0000, Kerin Millar wrote:
> > time for ((i=0; i < 1000; i++)); do X=x f | cat >/dev/null; done
> > time for ((i=0; i < 1000; i++)); do { X=x; f; } | cat >/dev/null; done
> >
> > Obviously, you may need to tune the number of iterations in order to incur
> > an acceptably substantive wall time.
>
> I'd also move the >/dev/null outside the loop. You're adding 1000x
> the number of times it takes to make that system call to the execution
> times, which might distort things a tiny bit.
I posted it so deliberately but, now that you mention it, I'm not entirely sure
what I was thinking. A sterling observation then.
--
Kerin Millar