Re: Is << faster than echo?
On 2007-05-25, tmp123 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.
Both of which are vastly slower than either of:
temp=${in#*;}
echo "${temp%%;*}"
Or:
IFS=\;
set -- $in
echo $2
> Knowns someone if this can be taken as a design rule, in the cases
> where time is a few important, like inside long loops?
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
|