{ # 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 #### 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 #### Rate kutsu davidrw_2 davidrw_1 ternary op_orig qm op_cmp2 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% --