Skip to content

Commit

Permalink
compare_lists_by_item: lift a var outside the loop
Browse files Browse the repository at this point in the history
This can be a _very_ hot loop so even small
differences add up.
  • Loading branch information
shawnlaffan committed Feb 24, 2024
1 parent 0c34d12 commit 4168546
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/Biodiverse/Common.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,7 @@ sub compare_lists_by_item {
\my %base_ref = $args{base_list_ref};
\my %comp_ref = $args{comp_list_ref};
\my %results = $args{results_list_ref};
my ($diff, $increment);

COMP_BY_ITEM:
foreach my $index (keys %base_ref) {
Expand All @@ -2428,8 +2429,8 @@ sub compare_lists_by_item {
# compare at 10 decimal place precision
# this also allows for serialisation which
# rounds the numbers to 15 decimals
my $diff = $base_ref{$index} - $comp_ref{$index};
my $increment = $diff > DEFAULT_PRECISION_SMALL ? 1 : 0;
$diff = $base_ref{$index} - $comp_ref{$index};
$increment = $diff > DEFAULT_PRECISION_SMALL ? 1 : 0;

# for debug, but leave just in case
#carp "$element, $op\n$comp\n$base " . ($comp - $base) if $increment;
Expand Down

0 comments on commit 4168546

Please sign in to comment.