Re: initialize a hash
- From: "Dr.Ruud" <rvtol+news@xxxxxxxxxxxx>
- Date: Wed, 16 Aug 2006 00:22:41 +0200
Paul Lalli schreef:
Dr.Ruud:
I am investigating what is the fastest way to set up a hash, with the
keys coming from an array, and all values set to a constant like 1.
x1s => sub { my %a ; @a{ @list } = (1) x @list },
Yes, that's more what I am looking for. Thanks, Uri and Anno too of
course.
My 'list' and 'range' (and 'empty') were meant as speed references; they
don't set all values to the same (and defined) constant.
Rate mapB mapE list for x1s range empty
mapB 243/s -- -0% -9% -41% -48% -48% -62%
mapE 243/s 0% -- -8% -41% -48% -48% -62%
list 266/s 10% 9% -- -36% -43% -43% -58%
for 412/s 70% 69% 55% -- -11% -12% -35%
x1s 464/s 91% 90% 74% 12% -- -1% -27%
range 467/s 93% 92% 76% 13% 1% -- -27%
empty 638/s 163% 162% 140% 55% 38% 37% --
On your system, 'list' isn't as near to 'for' as on the freebsd with
perl 5.8.6 here.
I still wish there were a construct that would deliver as many
<constant>s as requested.
Something like C<1...undef> maybe, but no: that would break existing
code.
This one is (just 1 or 2%) faster than "empty":
empty1 => sub { my %a ; @a{ @list } = undef },
--
Affijn, Ruud
"Gewoon is een tijger."
.
- Follow-Ups:
- Re: initialize a hash
- From: Brian McCauley
- Re: initialize a hash
- References:
- initialize a hash
- From: Dr.Ruud
- Re: initialize a hash
- From: Paul Lalli
- initialize a hash
- Prev by Date: cgi-bin/guestbook.pl
- Next by Date: Re: Accessing a container objects state from aggregated objects
- Previous by thread: Re: initialize a hash
- Next by thread: Re: initialize a hash
- Index(es):
Relevant Pages
|