Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: Re: Re: Removing Duplicate Array Elements!!!

by tachyon (Chancellor)
on Sep 27, 2001 at 20:36 UTC ( #115146=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Removing Duplicate Array Elements!!!
in thread Removing Duplicate Array Elements!!!

As you say, the slice method is faster again. I will be using it from now on. Thanks.

use Benchmark; @a= (0..100,0..100); $mine = <<'CODE'; my %hash; @hash{$_}++ for @a; @a = keys %hash; CODE $yours1 = <<'CODE'; my %hash; @hash{@a} = (); @a = keys %hash; CODE $yours2 = <<'CODE'; my %hash; @hash{@a} = @a; @a = values %hash; CODE $his = <<'CODE'; my %hash; map { $hash{$_}=1 } @a; @a = keys %hash; CODE timethese ( 10000, { 'mine' => $mine, 'yours1' => $yours1, 'yours2' => $yours2, 'his' => $his } ); __END__ C:\>perl test.pl Benchmark: timing 10000 iterations of his, mine, yours1, yours2... his: 17 wallclock secs (17.03 usr + 0.00 sys = 17.03 CPU) @ 58 +7.20/s (n=10000) mine: 15 wallclock secs (15.05 usr + 0.00 sys = 15.05 CPU) @ 66 +4.45/s (n=10000) yours1: 12 wallclock secs (11.76 usr + 0.00 sys = 11.76 CPU) @ 85 +0.34/s (n=10000) yours2: 15 wallclock secs (14.78 usr + 0.00 sys = 14.78 CPU) @ 67 +6.59/s (n=10000) C:\>

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


Comment on Re: Re: Re: Re: Removing Duplicate Array Elements!!!
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://115146]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-09-22 07:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (182 votes), past polls