use strict; use warnings; use Benchmark qw(cmpthese); use List::MoreUtils; my @data; # AB for ( 1 .. 1e4 ) { push @data, int( rand 1e6 ); } my @lines; # BU for ( 1 .. 1e3 ) { my $line = int( rand 1e6 ); $line .= chr(9) . int( rand 1e6 ) while length( $line ) < 4096; push @lines, $line; } my @values = map {int rand 10} 1 .. 1000; # GF my $data; $data = \@data; #$data = \@lines; #$data = \@values; sub uniq1 { # copied from List::MoreUtils my %h; map { $h{$_}++ == 0 ? $_ : () } @_; } sub uniq2 { my %h; grep { $h{$_}++ == 0 } @_; } sub uniq3 { # OP my %h; grep {$h{$_} = undef} @_; keys %h; } sub uniq4 { # BrowserUk my %h; undef @h{ @_ }; keys %h; } cmpthese(-1, { 'uniqM' => sub { my @uniq = List::MoreUtils::uniq(@$data) }, 'uniq1' => sub { my @uniq = uniq1(@$data) }, 'uniq2' => sub { my @uniq = uniq2(@$data) }, 'uniq3' => sub { my @uniq = uniq3(@$data) }, 'uniq4' => sub { my @uniq = uniq4(@$data) }, });