I can't reproduce this (linux, 5.20.2):
use Time::HiRes qw(time);
my $n = $ARGV[0];
my %h;
for (1..$n) {
my $key = sprintf "%06d", $_;
$h{$key} = 1;
}
my @a;
my $t1 = time;
@a = keys %h;
my $t2 = time;
printf "time = %.3f; secs per 1M keys: %.3f\n",
($t2-$t1), ($t2-$t1) / $n * 1_000_000;
I get the following, which shows that the time per key is nearly constant:
$ perl foo 1000000
time = 0.400; secs per 1M keys: 0.400
$ perl foo 2000000
time = 0.845; secs per 1M keys: 0.423
$ perl foo 4000000
time = 1.752; secs per 1M keys: 0.438
$ perl foo 8000000
time = 3.792; secs per 1M keys: 0.474
$ perl foo 16000000
time = 9.213; secs per 1M keys: 0.576
Dave.