C:\test>826814
Total size in ram: 15132924
1e6 lookups took 1.619
size on disk (excluding blocking): 65340000
Time to construct hash from (ram) file: 14.578
####
C:\test>826814-b
Total size in ram: 8871552
1e6 lookups took 0.813
size on disk (excluding blocking): 8822720
Time to construct hash from storable (ram) file: 0.039
####
#! perl -slw
use strict;
use Time::HiRes qw[ time ];
use Devel::Size qw[ total_size ];
my %db;
for my $ac ( 100 ..999 ) {
$db{ $ac }{ $_ } = '1234' for 100 .. 4999;
}
print "Total size in ram: ", total_size( \%db );
my $start = time;
for ( 1 .. 1e6 ) {
my $info = $db{ 100+int(rand 800) }{ 100+int(rand 4900) };
}
printf "1e6 lookups took %.3f\n", time() - $start;
my $ram = chr(0) x 6.5e7;
open RAM, '+<', \$ram;
seek RAM, 0, 0;
for my $ac ( 100 .. 999 ) {
for my $pre ( 100 .. 4999 ) {
printf RAM "$ac,$pre, $db{ $ac }{ $pre }\n";
}
}
print "size on disk (excluding blocking): ", length $ram;
seek RAM, 0, 0;
$start = time;
my %db2;
m[([^,]+),([^,]+),([^,]+)] and $db{ $1 }{ $2 } = $3 while ;
printf "Time to construct hash from csv (ram) file: %.3f\n", time()-$start;
__END__
C:\test>826814
Total size in ram: 15132924
1e6 lookups took 1.619
size on disk (excluding blocking): 65340000
Time to construct hash from (ram) file: 14.578
####
#! perl -slw
use strict;
use Storable qw[ freeze thaw ];
use Time::HiRes qw[ time ];
use Devel::Size qw[ total_size ];
my @db;
for my $ac ( 100 ..999 ) {
$db[ $ac - 100 ] = pack 'S*', (1234) x 4899;
}
print "Total size in ram: ", total_size( \@db );
my $start = time;
for ( 1 .. 1e6 ) {
my $info = unpack 'S', substr $db[ int( rand 800 ) ], 2*( int( rand 4900 ) ), 2;
}
printf "1e6 lookups took %.3f\n", time() - $start;
my $ram = freeze \@db;
print "size on disk (excluding blocking): ", length $ram;
$start = time;
my @db2 = @{ thaw( $ram ) };
printf "Time to construct hash from storable (ram) file: %.3f\n", time()-$start;
__END__
C:\test>826814-b
Total size in ram: 8871552
1e6 lookups took 0.813
size on disk (excluding blocking): 8822720
Time to construct hash from storable (ram) file: 0.039