From 41685467e60578063f487d34dbfb267970cad42a Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Sat, 24 Feb 2024 12:44:17 +1100 Subject: [PATCH] compare_lists_by_item: lift a var outside the loop This can be a _very_ hot loop so even small differences add up. --- lib/Biodiverse/Common.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Biodiverse/Common.pm b/lib/Biodiverse/Common.pm index 16cd4d377..feb2d0f38 100644 --- a/lib/Biodiverse/Common.pm +++ b/lib/Biodiverse/Common.pm @@ -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) { @@ -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;