casevsswitch

JavaScript performance comparison

Revision 13 of this test case created

Preparation code

<script>
  var objDictionary = {
    1 : "The string is for case 'a'",
    2 : "The string is for case 'b'",
    3 : "The string is for case 'c'",
    4 : "The string is for case 'd'",
    5 : "The string is for case 'e'",
    6 : "The string is for case 'f'",
    7 : "The string is for case 'g'",
    8 : "The string is for case 'h'",
    9 : "The string is for case 'i'",
    10 : "The string is for case 'j'"
  }
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Lookup by object
strValue = objDictionary[10];
 
pending…
Lookup by switch
strKey = 10;
switch( strKey ) {
  case 1 :
    strResult = "The string is for case 'a'";
    break;
   
  case 2 :
    strResult = "The string is for case 'b'";
    break;
   
  case 3 :
    strResult = "The string is for case 'c'";
    break;
   
  case 4 :
    strResult = "The string is for case 'd'";
    break;
   
  case 5 :
    strResult = "The string is for case 'e'";
    break;
   
  case 6 :
    strResult = "The string is for case 'f'";
    break;
   
  case 7 :
    strResult = "The string is for case 'g'";
    break;
   
  case 8 :
    strResult = "The string is for case 'h'";
    break;
   
  case 9 :
    strResult = "The string is for case 'i'";
    break;
   
  case 10 :
    strResult = "The string is for case 'j'";
    break;
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment