in reply to Re: How to speed up a nested loop?
in thread How to speed up a nested loop?

Wouldn't i have to get my $y value by dividing through 16 then? I'd figure that'd royally mess up the performance.

Replies are listed 'Best First'.
Re^3: How to speed up a nested loop?
by apl (Monsignor) on Sep 18, 2008 at 09:44 UTC
    16 == 2^4, so I'd use $ry = $tile_index >> 4;

    Bit-shifts are a lot less expensive than divison.

      Unless the compiler or processor already performs that optimisation. In any case a shift is seldom faster than an increment.


      Perl reduces RSI - it saves typing
      Have to agree with GF here, i don't think that'll do much, especially as it'd actually increase the amount of times that rx will have to be calculated again. (See replies below.) Still thanks for mentioning the shift thing, didn't know that. :)