[ create a new paste ] login | about

Link: http://codepad.org/ewur5YjT    [ raw code | fork ]

Perl, pasted on Jul 5:
#!/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;


Create a new paste based on this one


Comments: