in reply to Re: Find unique elements in an array
in thread Find unique elements in an array
Calling undef on a hash slice is faster still.
gives meuse Benchmark qw(:all) ; my @a; push @a, int (rand(10)) foreach 1..100; my %unique; my @awd; cmpthese($1000, { 'jc' => sub { foreach my $thingy (@a) { $unique{$thingy} = 1 +; } @awd = keys %unique; }, 'mk' => sub { @unique{ @a} = 1; @awd = keys %unique; }, 'bt' => sub { undef(@unique{@a}); @awd = keys %unique; }, });
(Incidentally that is a truely bizarre indent style.)Rate jc mk bt jc 16556/s -- -54% -62% mk 36080/s 118% -- -18% bt 44007/s 166% 22% --
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Find unique elements in an array
by BrowserUk (Patriarch) on Apr 04, 2004 at 22:28 UTC | |
by tilly (Archbishop) on Apr 05, 2004 at 04:25 UTC | |
by BrowserUk (Patriarch) on Apr 05, 2004 at 05:33 UTC |
In Section
Cool Uses for Perl