Ok, I give up.
I certainly agree that replacing 'memory access with cheap operator'
is a good idea and obviously would be faster.
Here's some snips of benchmarks comparing the two:
@a=(1,2,3,0); $x=0; $m=4;
timethese(-10,{ ixwheel=> q{ $x = $a[$x] }
modby2x1=> q{ $x = (++$x) & $m} });
ixwheel: 434505.60/s
modby2x1: 391856.16/s
timethese(-10,{ ixwheel=> q{ $x=$a[$x] }
modby2x2=> q{ $x++; $x &= $m }});
ixwheel: 433011.28/s
modby2x2: 539474.07/s
Well, ok. For some reason the 2 statement version is much faster
than the 1 statement one (($x+1) was even slower than (++$x)!).
But now look what happens when they're used as an index:
timethese(-10,{ ixwheelix=> q{ $b[ $x=$a[$x] ] = $x }
modby2x2ix=> q{ $b[$x++] = $x; $x &= $m }});
ixwheelix: 262030.67/s
modby2x2ix: 220259.36/s
Again, this seemed to be the fastest of the variations.
But then, I'm using perl 5.05003 on a sparc solaris, YMMV.
???????????,
p
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.