bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Does gawk optimize length(row) in for-loop?


From: arnold
Subject: Re: [bug-gawk] Does gawk optimize length(row) in for-loop?
Date: Sat, 25 Mar 2017 12:13:18 -0600
User-agent: Heirloom mailx 12.4 7/29/08

Peng Yu <address@hidden> wrote:

> Hi, I have the following two code snippets. The first one takes the
> length() out of the loop. I am wondering whether gawk does any
> optimization for case 2 so that length() is only called once. Or
> length() will be called multiple times in case 2?

In case 2, length() will be called each time around the loop. It
would be a mistake to "optimize" that out since row could be
changed within the loop itself.

Arnold

> # code snippet 1
>     nf = length(row)
>     for(i=dat_col; i<=nf; ++i) {
>       data[i] += row[i]
>     }
>
> # code snippet 2
>     for(i=dat_col; i<=length(row); ++i) {
>       data[i] += row[i]
>     }
>
> -- 
> Regards,
> Peng



reply via email to

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