Boogman has asked for the wisdom of the Perl Monks concerning the following question:
As an lvalue keys allows you to increase the number of hash buckets allocated for the given hash. This can gain you a measure of efficiency if you know the hash is going to get big.
use Benchmark; timethese( 100, {with => q{ my %hash; keys( %hash ) = keys( %hash ) = 10000; foreach $i (1 .. 10000) { $hash{"key$i"} = $i; } }, without => q{ my %hash; foreach $i (1 .. 10000) { $hash{"key$i"} = $i; } }, });
Benchmark: timing 100 iterations of with, without... with: 14 wallclock secs (13.73 usr + 0.04 sys = 13.77 CPU) @ 7 +.26/s (n=100) without: 14 wallclock secs (13.86 usr + 0.00 sys = 13.86 CPU) @ 7 +.22/s (n=100)
vs.1/16384 2/16384 3/16384 4/16384 5/16384 6/16384 7/16384 8/16384 9/16384 10/16384
Am I doing something wrong in my benchmark? Or is there some magic going on behind the scenes of hashes that make expanding the hash not an issue? Thanks4/8 5/8 6/8 7/8 7/8 7/8 7/8 7/8 12/16 13/16 13/16 13/16 etc...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Using keys to increase hash efficiency
by lhoward (Vicar) on Jul 28, 2000 at 18:47 UTC | |
RE: Using keys to increase hash efficiency
by mikfire (Deacon) on Jul 28, 2000 at 20:09 UTC | |
Re: Using keys to increase hash efficiency
by Boogman (Scribe) on Jul 28, 2000 at 21:24 UTC | |
Re: Using keys to increase hash efficiency
by ferrency (Deacon) on Jul 28, 2000 at 20:50 UTC | |
by Anonymous Monk on Jul 29, 2000 at 02:39 UTC |