With the same assumption as moritz's (that neither list has duplicate entries), you might try this:
sub Intersection { my ($refA, $refB) = @_; my %B; @B{@$refB} = (1) x @$refB; # hash the second list my $intersects; for(@$refA) { ++$intersects if exists $B{$_} # 'exists' is fast! } return $intersects; }
In reply to Re: improving the speed
by hbm
in thread improving the speed
by perl_lover_always
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |