Performance JS If Else/Switch/Object (v29)

Revision 29 of this benchmark created by Jonas on


Setup

id = "yahoo";
    url = "";

Test runner

Ready to run.

Testing in
TestOps/sec
If else
 if(id==="camelCase"){
    url = "http://www.thecamelcase.com";
}else if (id==="jsFiddle"){
    url = "http://jsfiddle.net/";
}else if (id==="cricInfo"){
    url = "http://cricinfo.com/";
}else if (id==="apple"){
    url = "http://apple.com/";
}else if (id==="yahoo"){
    url = "http://yahoo.com/";
}   
ready
Switch
switch (id) {
case 'camelCase':
    url = "http://www.thecamelcase.com";
    break;
case 'jsFiddle':
    url = "http://www.jsfiddle.net";
    break;
case 'cricInfo':
    url = "http://www.cricinfo.com";
    break;
case 'apple':
    url = "http://www.apple.com";
    break;
case 'yahoo':
    url = "http://www.yahoo.com";
    break;
}
 
ready
Object
var sites = {
camelCase : "http://www.thecamelcase.com",
jsFiddle: "http://www.jsfiddle.net",
cricInfo: "http://www.cricinfo.com",
apple: "http://www.apple.com",
yahoo: "http://www.yahoo.com"
};
url = sites[id];
 
ready
Direct Object
var sites = {
    camelCase : "http://www.thecamelcase.com",
    jsFiddle: "http://www.jsfiddle.net",
    cricInfo: "http://www.cricinfo.com",
    apple: "http://www.apple.com",
    yahoo: "http://www.yahoo.com"
}[id];
 
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.