in reply to Re: A better way of lookup?
in thread A better way of lookup?

There's another possible micro optimization. You could change the last line of the second group to just return 7200000 as you already know v is less then 64800000. There's no point testing it again.

# replace elsif( $v < 64800000 ) { return 7200000; } #with else { return 7200000; }

BTW that's an interesting result that elsif is quicker, did you test them in isolation? What improvement did the partial binary chop make compared with the elsif?

Replies are listed 'Best First'.
Re^3: A better way of lookup?
by flexvault (Monsignor) on Apr 26, 2015 at 17:36 UTC

    RichardK,

    Actually, both outer 'if / else' conditional statements could be reduced to just 'return ...' since each previous test did a 'return...' if the test was 'true'.

      BTW that's an interesting result that elsif is quicker, did you test them in isolation?
    Interestingly, use of the 'elsif' gave the most performance improvement! Someone on PerlMonks many years ago showed how it was better, all I did was remember and continue to use it in my scripts.

      What improvement did the partial binary chop make compared with the elsif?

    Not as much of an improvement as the 'elsif', but since BrowserUk may have more information about the frequency of the inputs, I left it in with the hope that it would help. Another consideration is that BrowserUk uses 64bit Windows and I use mostly 32bit *nix. That's why the benchmarking is critical, since the results may be different in his environment. Please note, that I had to add brackets around the 'return' in order to compile his original script in my environment. YMMV!

    Regards...Ed

    "Well done is better than well said." - Benjamin Franklin