#!/usr/bin/perl

use strict;
use warnings;

use Benchmark;
use List::Util qw/shuffle/;

print "Perl version $]\n";

my $N = 6;
my $M = 10**$N;
my %subs;
for my $n ( 0 .. $N ) {
    my $m = 10**$n;
    keys( my %h ) = $m;    #preallocated the hash so it doesn't have to keep growing
    my $k = "aaaaaa";
    %h = ( map { $k++ => 1 } 1 .. $m );
    my @a = shuffle keys %h;
    if (@a != $M) {
	@a = (@a) x ($M / @a);
    }
    my $x;
    $subs{"10^$n keys"} = sub {
    	$x = $h{$_} for @a;
    };
}

Benchmark::cmpthese -3, \%subs;
