use strict; use warnings; use Benchmark qw(cmpthese); use constant type => 0; cmpthese (-1, { org => 'org ()', gf => 'gf ()', }); sub org { my $bz = 0; my $bx = 0; my $by = 0; my $changed; my @tiles; my @type_data; for my $y (0 .. 15) { for my $x (0 .. 15) { # this calculates the tile index we are currently at, # using the x and y coords in this block my $tile_index = $y + ($x * 16); # this calculates the real x and y values of this tile my $rx = ($bx * 16) + $x; my $ry = ($by * 16) + $y; # insert type data into the internal map array and # note that there was change in this block if applicable if (!defined $tiles[$rx][$ry][$bz][type] || $tiles[$rx][$ry][$bz][type] != $type_data[$tile_index]) { $changed = 1; $tiles[$rx][$ry][$bz][type] = $type_data[$tile_index]; } } } } sub gf { my $bz = 0; my $bx = 0; my $by = 0; my $changed; my @tiles; my @type_data; my $bxScaled = $bx * 16; my $byScaled = $by * 16; for my $x (0 .. 15) { my $xScaled = 16 * $x; for my $y (0 .. 15) { # this calculates the tile index we are currently at, # using the x and y coords in this block my $tile_index = $y + $xScaled; # this calculates the real x and y values of this tile my $rx = $bxScaled + $x; my $ry = $byScaled + $y; # insert type data into the internal map array and # note that there was change in this block if applicable my $tile = $tiles[$rx][$ry][$bz][type]; if (!defined $tile || $$tile != $type_data[$tile_index]) { $changed = 1; $$tile = $type_data[$tile_index]; } } } } __END__ Rate org gf org 1372/s -- -29% gf 1939/s 41% --