in reply to Find unique elements in an array
The results areuse 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; }, });
Update: $1000 is a typo should be 1000. I'll keep it as is for comparisons with the following nodes. Thanks BrowserUK and tilly!Benchmark: running jc, mk for at least 3 CPU seconds... jc: 3 wallclock secs ( 3.14 usr + 0.00 sys = 3.14 CPU) @ 53 +5.67/s (n=20522) mk: 4 wallclock secs ( 3.27 usr + 0.00 sys = 3.27 CPU) @ 14 +937.00/s (n=48844) Rate jc mk jc 6536/s -- -56% mk 14937/s 129% --
-Mark
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Find unique elements in an array
by tilly (Archbishop) on Apr 04, 2004 at 20:25 UTC | |
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 | |
Re: Re: Find unique elements in an array
by ysth (Canon) on Apr 04, 2004 at 13:35 UTC | |
by kvale (Monsignor) on Apr 04, 2004 at 15:52 UTC | |
by ysth (Canon) on Apr 04, 2004 at 19:53 UTC | |
by ccn (Vicar) on Apr 04, 2004 at 16:54 UTC | |
Re: Re: Find unique elements in an array
by kappa (Chaplain) on Apr 04, 2004 at 21:04 UTC |