INTERESTING!
Maybe it doesn't hurt to program the way your brain really thinks...at least not this time. You see, I stripped down the MJD code to its barest form, exactly from the book. Then I removed the print statements from my own version which was just shared in the node previous to this node.
Surprise: despite the fact that I'm passing around a reference to my "$share" with each call, my code benches twice as fast. I'm betting it's because I'm not constantly recalculating the "$target".
Anyway, here's the benchmarks. I wonder what conclusions could be drawn. If I cared more, I'd run it through Devel::NYTprof and find out what's really going on and why it's faster to do it the way that makes the most sense to my dyslexic brain:
$ perl ./find_shares_myway_2.pl
Benchmark: timing 500000 iterations of test1...
test1: 16 wallclock secs (15.43 usr + 0.00 sys = 15.43 CPU) @ 32
+404.41/s (n=500000)
$VAR1 = {
'test1' => bless( [
16,
'15.43',
0,
0,
0,
500000
], 'Benchmark' )
};
$ perl ./find_shares.pl
Benchmark: timing 500000 iterations of test1...
test1: 31 wallclock secs (30.10 usr + 0.02 sys = 30.12 CPU) @ 16
+600.27/s (n=500000)
$VAR1 = {
'test1' => bless( [
31,
'30.1',
'0.02',
0,
0,
500000
], 'Benchmark' )
};
--
Tommy
$ perl -MMIME::Base64 -e 'print decode_base64 "YWNlQHRvbW15YnV0bGVyLm1lCg=="'
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
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.
|
|