That's what I expect from common sense, yes.
A quick benchmark seems to confirm this; asking an empty hash is much faster than asking a filled one, but the number of keys in the full hash seems to have no significant influence on the speed:
use strict;
use warnings;
use Benchmark qw(cmpthese);
for my $len (2..6) {
our (%full, %empty);
my $a = 'A';
$full{$a++} = $a while length($a) < $len;
print "\nLength $len with ", scalar(%full), "items\n";
cmpthese -1, {
full => sub {die unless %full},
empty => sub {die if %empty},
}
}
__END__
Length 2 with 22/32items
Rate full empty
full 1286220/s -- -77%
empty 5481192/s 326% --
Length 3 with 510/1024items
Rate full empty
full 1052183/s -- -82%
empty 5748771/s 446% --
Length 4 with 13961/32768items
Rate full empty
full 998734/s -- -84%
empty 6056132/s 506% --
Length 5 with 310721/524288items
Rate full empty
full 963764/s -- -83%
empty 5681139/s 489% --
Length 6 with 8655839/16777216items
Rate full empty
full 849541/s -- -86%
empty 6124859/s 621% --
Note that the number of hash items grows exponentially, while the number of iterations decreases linearly at best.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|