in reply to How to speed up a nested loop?

You could always foreach $tile_index ( 0 .. 255 ) and then calculate $rx and $ry...

Replies are listed 'Best First'.
Re^2: How to speed up a nested loop?
by Xenofur (Monk) on Sep 18, 2008 at 08:02 UTC
    Wouldn't i have to get my $y value by dividing through 16 then? I'd figure that'd royally mess up the performance.
      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. :)