in reply to Re^2: Advice for optimizing lookup speed in gigantic hashes
in thread Advice for optimizing lookup speed in gigantic hashes
By way of demonstration. Looking up 9000 words in a hash is 6X faster than splitting those same 9000 words out of a string:
$s = 'the quick brown fox jumps over the lazy dog' x 1000;; ++$h{ $_ } for qw[ the quick brown fox jumps over the lazy];; cmpthese -1,{ a => q[ my @words = split ' ', $s;], b => q[ my $n=0; $h{$_} && ++$n for (qw[ the quick brown fox jumps over the lazy dog ]) x 1000; ] };; Rate a b a 95.4/s -- -85% b 644/s 575% --
|
|---|