[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.
-
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.
|