[id://spurperl] is right, table lookup is fastest. Using the notation op for [id://PerlingTheUK|original poster], lt for "lookup table", and the rest obvious, the overall benchmark looks something like this:
Rate op4 op5 hv7 hv6 roy4 kaif lt
op4 64233/s -- -33% -33% -52% -57% -72% -76%
op5 96098/s 50% -- -0% -28% -36% -58% -64%
hv7 96399/s 50% 0% -- -28% -35% -58% -64%
hv6 134032/s 109% 39% 39% -- -10% -41% -50%
roy4 149447/s 133% 56% 55% 12% -- -34% -45%
kaif 227019/s 253% 136% 135% 69% 52% -- -16%
lt 270514/s 321% 181% 181% 102% 81% 19% --
Just be sure to initialize your table outside of your function, that is, initialize only once.
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.