Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
go ahead... be a heretic
 
PerlMonks  

Re: Optimization Help

by choroba (Abbot)
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;
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Optimization Help
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047515]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2014-04-17 10:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (444 votes), past polls