Jay
Jay

Reputation: 757

Improving javascript code performance

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

Upvotes: 0

Views: 55

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1075337

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.

Upvotes: 1

Related Questions