bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Magnitude of Order "For Loop" performance deltas based on syntax cha


From: Chet Ramey
Subject: Re: Magnitude of Order "For Loop" performance deltas based on syntax change
Date: Sun, 25 Sep 2016 15:01:33 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

On 9/24/16 8:29 AM, Christian Franke wrote:

> - Method-2 could be significantly speed up if the order of the array
> accesses is reversed:
> 
>   for (( i=0; i<N-1; i++)); do
>       if (( -(Pi[i] - Pi[i+1]) < min )); then
>           min=$((-(Pi[i]-Pi[i+1])))
>       fi
>   done
> 
> Result: ~3 seconds
> (using 'let' in the 'min' assignment failed with syntax error - Bug?)

I assume you mean that you used something like

        let min=-(Pi[i]-Pi[i+1])

That's a syntax error because `(' is a shell operator, and it needs to be
quoted if you want it to appear in a word.  Since `let' is a builtin, not
part of the shell syntax, you have to make sure that all arguments to it
are valid shell words.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]