#!/usr/local/bin/perl5.12.1 use strict; use Time::HiRes qw( gettimeofday ); print "\t Replicate Entire\tLoop Copy\tReplicate sub-Hash\n","-" x 70,"\n"; my $Lcnt = 1_000; for (my $i=30; $i<=256; $i+=32 ) { ## Populate the Hash my %Account = (); keys( %{ $Account{$i} } ) = $i; for my $cnt ( 0 .. $i ) { for my $id ( 0 .. $i ) { $Account{"$cnt"}{"$id"}="x" x (int(rand($i))+6); } } ## Lock the global hash %Account and Replicate the entire hash my $tm = gettimeofday; for ( 0 .. $Lcnt ) ## Just to get a big enough number to compare { my %TAccount = %Account; } $tm = sprintf("%.7f",(gettimeofday-$tm)/$Lcnt); ## Unlock the global hash %Account ## Lock the global hash %Account and loop copy the local hash from the global hash of hashes my $tm1 = gettimeofday; for ( 0 .. $Lcnt ) ## Just to get a big enough number to compare { my %TAccount = (); keys( %TAccount ) = $i; foreach my $key ( keys %{ $Account{$i} } ) { $TAccount{$key} = $Account{$i}{$key}; } } $tm1 = sprintf("%.7f",(gettimeofday-$tm1)/$Lcnt); ## Unlock the global hash %Account ## Lock the global hash %Account and replicate the local hash from the global hash of hashes my $tm2 = gettimeofday; for ( 0 .. $Lcnt ) ## Just to get a big enough number to compare { my %TAccount = %{ $Account{"$i"} }; } $tm2 = sprintf("%.7f",(gettimeofday-$tm2)/$Lcnt); ## Unlock the global hash %Account print $i, ":", scalar %Account, "\t$tm\t$tm1\t$tm2\n"; } 1;