Created
August 3, 2012 22:38
-
-
Save vovkasm/3252244 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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