in reply to A better way of lookup?

First, thanks to everyone who responded. I wasn't expecting much response to the question; and was surprised by the multitude of alternatives offered. Thank you all.

Upshot: I coded up several of the more distinct variations in JS and plugged them into the JS code and made a (probably clumsy and naive) attempt to measure the results; and the outcome was that I couldn't discern any consistent benefit from any of them.

Perhaps if I had more experience with JS; or if the table size was larger; but I suspect that JIT compilation and optimisation is playing a part here.

So, for now, I'm sticking with the crudely simple version I posted in the OP for this purpose, and I'll re-visit this thread next time I have the same problem either in Perl; or with a larger table size.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
  • Comment on Re: A better way of lookup? (Thanks and outcome.)

Replies are listed 'Best First'.
Re^2: A better way of lookup? (Thanks and outcome.)
by Anonymous Monk on Apr 27, 2015 at 22:43 UTC
    Probably the most sensible thing to do. It probably does not matter to the computer how you do it. What matters most is how you specify it to your colleagues. K.I.S.S. is usually the best-all-around approach ... unless and until ... you can prove "actual pain" (computer, or human) with regards to the approach that was taken.

      What I think is close to being the final version for this project, looks like this:

      const ms = 1, sec = 1000*ms, mn = 60*sec, hr = 60*mn, day = 24*hr, mth + = 30.4375*day, yr = 365.25*day; function _DateInterval( vv ) { if( vv < 25*sec ) return 2.5*sec; if( vv < 50*sec ) return + 5*sec; if( vv < 2.5*mn ) return 12.5*sec; if( vv < 3.75*mn ) return +25*sec; if( vv < 5*mn ) return 37.5*sec; if( vv < 10*mn ) return + 1*mn; if( vv < 20*mn ) return 2*mn; if( vv < 1*hr ) return + 5*mn; if( vv < 1.5*hr ) return 10*mn; if( vv < 3*hr ) return + 15*mn; if( vv < 6*hr ) return 30*mn; if( vv < 12*hr ) return + 1*hr; if( vv < 18*hr ) return 2*hr; if( vv < 1.5*day ) return + 3*hr; if( vv < 2.5*day ) return 6*hr; if( vv < 5*day ) return + 12*hr; if( vv < 10*day ) return 1*day; if( vv < 20*day ) return + 2*day; if( vv < 35*day ) return 4*day; if( vv < 70*day ) return + 7*day; if( vv < 140*day ) return 14*day; if( vv < 1*yr ) return + 1*mth; if( vv < 2*yr ) return 2*mth; if( vv < 2.5*yr ) return + 3*mth; if( vv < 5*yr ) return 6*mth; return 1*yr; }

      Suggestions -- especially re:JS -- welcomed.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
      In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked