Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Optimization Help

by choroba (Chancellor)
on Aug 01, 2013 at 23:25 UTC ( #1047515=note: print w/replies, xml ) Need Help??

in reply to Optimization Help

grep iterates over all the numbers from 0 to $#mapping. Stopping the loop as soon as the first inequality is found might speed the subroutine up, especially if the array is large and inequalities are not very rare. You can use a simple for loop instead:
for (0 .. $#mapping) { return 0 if $self->{Matrix}[$row_index][$_] != $other->{Matrix}[$mapping->[$row_index]][$mapping->[$_ +]]; } return 1;

Update: The hash dereference could also take some microseconds if repeated many times. As $row_index does not change, you can assign the values to variables:

my $self_row = $self->{Matrix}[$row_index]; my $other_row = $other->{Matrix}[$mapping->[$row_index]]; for (0 .. $#mapping) { return 0 if $self_row->[$_] != $other_row->[$mapping->[$_]]; } return 1;
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ