"Premature optimization is the root of all evil!"

Are you sure you do need to fiddle with these things? Does it make a 
measurable difference?

From:  [email protected]
> This may be merely a philosophical debate, but I have a 
> performance-related question regarding pre-allocation to hashes. 

That's the point. It's preallocation! That is it allows you to 
specify the number of keys before you insert them and thus prevent 
perl from having to rehash the keys several times as you add them one 
at a time. That's where it makes a difference. 

#!perl
keys %hh = 64;
for (aa..zz) {$c++; $h{$_}=1; $hh{$_}=1; print "$c : ".%h." - ".%hh."\n";exit 
if $cnt > 64};
__END__

As you can see the number of used buckets is the same for both hashes 
as soon as the number of keys is big enough to force perl to allocate 
the same number for the %h hash as you preallocated for %hh.

Jenda
===== [email protected] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to