Coming late to the game, I used a predefined hash lookup:
{ # closure for qm # build lookup hash my $point_step = 2000; my $point_max = 18000; my $quota_offset = 15; my %quota; foreach my $p ( 1..$point_max/$point_step ) { $quota{$p} = $p + $quota_offset; } sub qm { my ($points, $quota) = @_; # $points-1 handles "less than but not equal" $points = int(($points-1)/$point_step); if ( exists( $quota{$points} ) and ( $quota < $quota{$points} ) ) { return $quota{$points}; } else { return 15; } } # sub qm } # closure qm
I also ran this through the test script, and it checked out OK.

I used this version of stick2, which tested OK as well:

use constant STICK2 => [ 15, map( ($_) x 2, 15..23 ), (24) x 100 ]; sub stick2{ my $q = STICK2->[ 1 + $_[0] / 1000 ]; # changed to "<=", and "15" return $q <= $_[1] ? 15 : $q; } # sub stick2
Update: I added kutsu's to the mix, and fixed davidrw's davidrw_2 entry.

Here are the results:

Rate kutsu davidrw_2 davidrw_1 ternary op_orig qm op_c +mp2 stick2 kutsu 37118/s -- -19% -33% -92% -92% -94% - +94% -95% davidrw_2 45997/s 24% -- -18% -90% -90% -92% - +93% -94% davidrw_1 55762/s 50% 21% -- -88% -88% -90% - +91% -93% ternary 463776/s 1149% 908% 732% -- -1% -19% - +29% -41% op_orig 469008/s 1164% 920% 741% 1% -- -18% - +28% -41% qm 571464/s 1440% 1142% 925% 23% 22% -- - +12% -28% op_cmp2 650147/s 1652% 1313% 1066% 40% 39% 14% + -- -18% stick2 788323/s 2024% 1614% 1314% 70% 68% 38% +21% --
While qm isn't quite as fast as op_cmp2, it will scale better for more breakpoints.

If the OP can maintain stick2, I'd go with that. However, it might be unmaintainable by Common Folk.

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to Re: alternatives to if and series of elsif by QM
in thread alternatives to if and series of elsif by kiat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.