Skip to content

Instantly share code, notes, and snippets.

@vovkasm
Created August 3, 2012 22:38
Show Gist options
  • Save vovkasm/3252244 to your computer and use it in GitHub Desktop.
Save vovkasm/3252244 to your computer and use it in GitHub Desktop.
#!perl
use 5.016;
use warnings;
use Benchmark 'timethese';
use Judy::1 qw/Set Get Count Unset MemUsed/;
say 'fill array...';
my %H;
my $J;
my $idx = 0;
while ($idx < 0xFFFFFFFF) {
# fill ratio ~ 1 / 1000
Set($J, $idx);
$H{$idx} = undef;
$idx += 950 + int(rand(100));
}
say 'done...';
printf("Judy stats:\n\tCount all: %d\n\tCount (<=10000): %d\n\tMemUsage: %d\n", Count($J,0,-1), Count($J,0,10000), MemUsed($J));
say 'benchmark tests...';
my $a;
timethese(-2, {
'Judy' => sub { $a = Get($J, int(rand(0xFFFFFFFF))); },
'Hash' => sub { $a = exists $H{ int(rand(0xFFFFFFFF)) }; },
});
<>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment