drieux wrote:

> On Saturday, May 18, 2002, at 07:09 , Tagore Smith wrote:
>
> > You're on the right track. Try something like this:
> >
> > my @array=("aaa", "aaa", "bbb", "bbb", "aaa", "ccc", "aaa", "bbb",
"ccc")
> > my %hash;
> >
> > foreach my $item (@array){
> >     $hash{$item}++;
> > }
> >
> > Tagore Smith
>
> http://www.wetware.com/drieux/pbl/BenchMarks/uniqCounts.txt
>
> ok, so my OCD is benchmarking - but I would like to offer
> what I think may be a bit quicker - if speed is your Need...
>
>    #------------------------
>    #
>    sub haveMap {
>      my (@list) = @_;
>      my %seen = ();
>
>      map {$seen{$_}++} @list;
>
>      \%seen ;
>
>    } # end of haveMap

I have to admit that I'm not very compulsive about benchmarks- at least not
until I'm pretty sure that I'll need the performance. I also mistrust
benchmarks to some degree- what they tell you about one specific
circumstance may not be universally applicable, and making thorough
benchmarks is a black art that I am not a master of. I could be wrong about
this, but I thought that there were some performance issues with using map
for side effects on large arrays in current perl implementations. Something
along the lines of map using the stack to store the returned list. At any
rate it seems like at the very least the map uses extra space. If you're
really compulsive about benchmarking these things you might try this with a
really large array. I'm not compulsive enough about it to do it, and I'm
willing to trade a bit of performance for what is (to me at least) clearer
code.

Stylistically, I prefer not to use map for side effects, but I'm aware that
this is a contentious issue, and I'm not religious about it :). It's good to
be aware that it's an option- thanks for the link.

Tagore Smith



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to