in reply to Re^11: How to speed up a nested loop?
in thread How to speed up a nested loop?
in the inner loop. Which looks up index $rx, gets an array reference, looks up index $ry, etc....$tiles[$rx][$ry]...
I moved calculating $rx out of the loop and the lookup on $rx out of the loop with:
and then in the loop had:my $tiles_for_rx = ($tiles[$rx] ||= []);
which means that the lookup of index $rx doesn't happen in the inner loop any more....$tiles_for_rx->[$ry]...
If your inner loop executes 15 times for each iteration of the outer loop, you just lost 14 calculations of $rx, and 14 lookups on index $rx. Less work is generally faster.
|
|---|