0

Assume you have a webapp with a 1000000 user logins in an hour.

and the following code get executed on each user login :

if (DevMode) {
    // make an Ajax call
} else if (RealMode) {
    // make other Ajax call
} else {
    // Do something else
} 

Assuming that the DevMode login occurs only for 5% of the total user logins, is it more efficient to write the code as following:

 if (RealMode) {
    // make an Ajax call
} else if (DevMode) {
    // make other Ajax call
} else {
    // Do something else
} 

Thanks

4
  • 2
    Either way, the amount of time spent by JavaScript in that will be absolutely minuscule and it won't make any noticeable difference. Commented Oct 16, 2016 at 14:35
  • Okay, so DevMode is only 5%. What's the other 95%? 95% RealMode and 0% neither? 5% RealMode and 90% neither? Commented Oct 16, 2016 at 14:37
  • In average you have like just 7 login connections per minute. Set aside your optimization case, you have enormous amount of time to handle them in every way you like. Commented Oct 16, 2016 at 14:41
  • if we assume I have 1,000,000 in an hour ? does that make a difference ? does avoiding doing multiple checks could improve performance ? Commented Oct 16, 2016 at 14:44

1 Answer 1

1

Assuming that RealMode is the 95% case (you haven't actually said whether it's RealMode or else) then: Well, yes, because you avoid doing a check that will be false 95% of the time.

It won't matter that it's more efficient, though. Testing a variable for truthiness is really, really, really, really, really fast.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.