Your benchmark is including the loop overhead - which is appropriate for "real" code, but dilutes the difference between the two access methods. Altering the appropriate parts of your code to:
my $lookup = '
_____
';
$lookup =~ s/_____/'$a = $contracts{1}[0];' x NUM_ACCESSES/e;
my $refit = '
my $r = $contracts{1};
_____
';
$refit =~ s/_____/'$a = $r->[0];' x NUM_ACCESSES/e;
and using your last test set I get:
Rate lookup refit
lookup 245666/s -- -32%
refit 360597/s 47% --
which is double the difference shown with the loop overhead included, and is comparable with the result from my benchmark.
Ain't benchmarks fun, almost as good as statictics! :-D
DWIM is Perl's answer to Gödel
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.