#! perl -sw use strict; use Benchmark::Timer; my $timer = Benchmark::Timer->new(skip => 1); local $\=$/; sub intersect (\@\@) { my ($aryRef1, $aryRef2) = @_; my %count = (); $count{$_}++ foreach @$aryRef1, @$aryRef2; return grep{ $count{$_} == 1 } keys %count; } my @aryBase = (1 .. 28000); my %hashBase; @hashBase{@aryBase} = undef; my @array2 = (1..1000, 1..100); # create some duplicates with duplicates for (0..100){ my @array1 = @aryBase; $timer->start('faq'); my @dup = intersect( @array1, @array2 ); $timer->stop('faq'); } for (0..100){ my %hashAry = %hashBase; $timer->start('delete'); my @dup = delete @hashAry{@array2}; $timer->stop('delete'); } $timer->report; @aryBase = intersect( @aryBase, @array2 ); print '\@aryBase contains ', scalar @aryBase, ' elements after intersect'; delete @hashBase{@array2}; print '\@hashBase contains ', scalar keys %hashBase, ' elements after intersect'; __END__ #output C:\test>207632 100 trials of faq (103.692s total), 1.037s/trial 100 trials of delete (881.000ms total), 8.810ms/trial \@aryBase contains 27000 elements after intersect \@hashBase contains 27000 elements after intersect C:\test>