[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH][RFC] New 'true' program
From: |
Bob Proulx |
Subject: |
Re: [PATCH][RFC] New 'true' program |
Date: |
Sat, 20 Nov 2004 11:24:25 -0700 |
User-agent: |
Mutt/1.5.6+20040907i |
Andreas Schwab wrote:
> James Youngman writes:
> > Paul Eggert wrote:
> > > If small size is all you want, I can do a lot better than that:
[Paul says 10 bytes. James says zero bytes.]
> This is not necessarily the best one.
>
> $ time ./true
> 0.00user 0.00system 0m0.02selapsed 9.60%CPU
> $ time /bin/true
> 0.00user 0.00system 0m0.00selapsed 100.00%CPU
But if size is all you want then I think it is hard to do worse than
zero size. As an optimization it is illustrative of the classic
tradeoffs between space and time.
However a zero sized file is not really portable. It depends upon the
user's shell to interpret the file after the system exec of it has
failed. It relies upon the user running a compatible shell. Who
knows what random shell the user will be running? If the user is
running an incompatible shell that does something different then the
zero sized 'true' fails. You can't count on the zero sized file
operating correctly. Since size is not the only thing you need to
optimize for the zero byte case is not good in the general case.
The problems of being portable is one of the reasons 'false' is
sometimes joked to be more portable than 'true'. If it fails to work
then it is still false.
By the way, on my system[1]:
: > true.usershell ; chmod a+x true.usershell
time ./true.usershell
real 0m0.017s
user 0m0.000s
sys 0m0.001s
echo "#!/bin/sh" > true.binsh ; chmod a+x true
time ./true.binsh
real 0m0.005s
user 0m0.002s
sys 0m0.003s
time /bin/true
real 0m0.001s
user 0m0.000s
sys 0m0.001s
So at a cost of only 10 bytes you can save some real time. And as
Andreas points out the binary version is the fastest.
By the way, I love it that it takes three digits to provide any
measurement at all of the time consumed. So unlike the systems of
even a few years ago.
Bob
[1] Debian GNU/Linux pure 64-bit on Athlon64 3200+ 2.2GHz
Re: [PATCH][RFC] New 'true' program, Alfred M. Szmidt, 2004/11/20
Re: [PATCH][RFC] New 'true' program, Felipe W Damasio, 2004/11/21
- Re: [PATCH][RFC] New 'true' program, Paul Eggert, 2004/11/21
- Re: [PATCH][RFC] New 'true' program, Alfred M. Szmidt, 2004/11/21
- Re: [PATCH][RFC] New 'true' program, Felipe W Damasio, 2004/11/23
- Re: [PATCH][RFC] New 'true' program, Alfred M. Szmidt, 2004/11/23
- Re: [PATCH][RFC] New 'true' program, Ricardo Nabinger Sanchez, 2004/11/23
- Re: [PATCH][RFC] New 'true' program, Alfred M. Szmidt, 2004/11/23
- Re: [PATCH][RFC] New 'true' program, Alfred M. Szmidt, 2004/11/23
Re: [PATCH][RFC] New 'true' program, Alfred M. Szmidt, 2004/11/20