Guys I have a couple of questions:
- Is there a performance difference in JavaScript between a
switchstatement and anif...else? - If so why?
- Is the behavior of
switchandif...elsedifferent across browsers? (FireFox, IE, Chrome, Opera, Safari)
The reason for asking this question is it seems that I get better performance on a switch statement with approx 1000s cases in Firefox.
Edited Unfortuantly this is not my code the Javascript is being produced serverside from a compiled library and I have no access to the code. The method that is producing the javascript is called
CreateConditionals(string name, string arrayofvalues, string arrayofActions)
note arrayofvalues is a comma separated list.
what it produces is
function [name] (value) {
if (value == [value from array index x]) {
[action from array index x]
}
}
Note: where [name] = the name passed into the serverside function
Now I changed the output of the function to be inserted into a TextArea, wrote some JavaScript code to parse through the function, and converted it to a set of case statements.
finally I run the function and it runs fine but performance differs in IE and Firefox.