Skip to content

Instantly share code, notes, and snippets.

@vovkasm
Created October 22, 2012 20:07
Show Gist options
  • Save vovkasm/3933779 to your computer and use it in GitHub Desktop.
Save vovkasm/3933779 to your computer and use it in GitHub Desktop.
try benchmark berkeleydb hash impl
#!perl
use 5.016;
use Benchmark qw/timethis/;
use BerkeleyDB;
use Data::UUID;
my $ug = Data::UUID->new;
my %h0;
my %h1;
tie %h1, 'BerkeleyDB::Hash';
my $fill = 100000;
my $nsum = $fill;
for (my $i=0; $i<20; $i++, $fill*=2, $nsum+=$fill) {
my $k0 = fill_n(\%h0, $fill);
my $k1 = fill_n(\%h1, $fill);
my $t0 = timethis(-1, sub { my $val = $h0{$k0}; }, "plain", "none");
my $t1 = timethis(-1, sub { my $val = $h1{$k1}; }, "bdb", "none");
printf("%10d\t%5.0f/s\t%5.0f/s\n", $nsum, $t0->iters/$t0->cpu_a, $t1->iters/$t1->cpu_a);
}
sub fill_n {
my ($h, $num) = @_;
my $testkey;
for (my $i=0; $i < $num; $i++) {
my $key = $ug->create_str;
$h->{$key} = rand(100);
$testkey = $key if $i == 10;
}
return $testkey;
}
[vovkasm@vov ~/work/bench]$ perl bench-berkeleydb.pl
100000 5100046/s 226938/s
300000 4505881/s 229993/s
700000 5177630/s 233712/s
1500000 5389044/s 225305/s
CPU: 0.4% user, 0.0% nice, 2.7% system, 0.1% interrupt, 96.7% idle
Mem: 1052M Active, 434M Inact, 6038M Wired, 144M Cache, 128M Buf, 229M Free
ARC: 4603M Total, 652M MRU, 2836M MFU, 151M Anon, 115M Header, 850M Other
Swap: 16G Total, 171M Used, 16G Free, 1% Inuse
PID USERNAME THR PRI NICE SIZE RES STATE C TIME WCPU COMMAND
95050 vovkasm 1 22 0 514M 483M tx->tx 1 2:45 3.37% perl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment