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)
####
1/16384
2/16384
3/16384
4/16384
5/16384
6/16384
7/16384
8/16384
9/16384
10/16384
####
4/8
5/8
6/8
7/8
7/8
7/8
7/8
7/8
12/16
13/16
13/16
13/16
etc...