Whilst true, it pales compared to the inefficiency of executing external commands. I've always preferred the (( a = a + 1 )) construct because it is slightly more readable. Nice to know that there's a performance reason for doing it too. Thanks for sharing.

Phil


Roland Mainz wrote:
Peter Tribble wrote:
On Thu, Sep 10, 2009 at 8:38 AM, Raymond Wong<raym...@gmail.com> wrote:
[snip]
while read a
do
       line=$(($line+1))
done

This will run even faster if you remove the '$', put the assignment
inside the arithmetric expression and declare "line" as integer
variable, e.g. ...
-- snip --
integer line=0

while read a ; do
       (( line=line+1 ))
done
-- snip --
These optimisations make sure that the shell won't do any unneccesary
string-to-integer and integer-to-string conversions which consume lots
of time. For floating-point values they are even a huge problem since
strings used base10 and the internal IEEE754 floats use base2 and the
string-to-float and float-to-string conversions trigger rounding
problems...

----

Bye,
Roland


_______________________________________________
perf-discuss mailing list
perf-discuss@opensolaris.org

Reply via email to