Afficher un message
Vieux 25/05/2007, 23h51   #5
sjdevnull@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is << faster than echo?

On May 25, 12:28 pm, tmp123 <tmp...@menta.net> wrote:
> Hello,
>
> After made the following test:
>
> $ cat foo.sh
> #!/usr/bin/bash
> #
> in="a;b;c"
>
> time echo $in | cut -d ';' -f 2
>
> time cut -d ';' -f 2 <<END
> $in
> END
>
> $ ./foo.sh
> b
>
> real 0m0.046s
> user 0m0.045s
> sys 0m0.046s
> b
>
> real 0m0.032s
> user 0m0.030s
> sys 0m0.015s
>
> it seems that use of here documents is a few faster than echo and
> pipeline.
>
> Knowns someone if this can be taken as a design rule, in the cases
> where time is a few important, like inside long loops?
>
> Thanks.


Putting both alternatives into a loop of 100 iterations gives me
(first is the "echo" version) 3 runs indicating odd results. "time"
is probably not accounting the parent-shell's here-document to the
subprocess's user/sys time, since I'm consistently seeing lower user/
sys for the here-document version but higher wall times.
[sumner@localhost sumner]$ bash t.sh

real 0m1.038s
user 0m0.085s
sys 0m0.203s

real 0m1.334s
user 0m0.072s
sys 0m0.203s
[sumner@localhost sumner]$ bash t.sh

real 0m1.158s
user 0m0.075s
sys 0m0.213s

real 0m1.767s
user 0m0.069s
sys 0m0.210s
[sumner@localhost sumner]$ bash t.sh

real 0m0.528s
user 0m0.082s
sys 0m0.210s

real 0m1.341s
user 0m0.074s
sys 0m0.202s

  Réponse avec citation
 
Page generated in 0,05913 seconds with 9 queries