HashTable vs Switch Statment

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var states = [
  				"testCase1","testCase2","testCase3","testCase4","testCase5","testCase6","testCase7",
  				"testCase1","testCase2","testCase3","testCase4","testCase5","testCase6","testCase7",
  				"testCase1","testCase2","testCase3","testCase4","testCase5","testCase6","testCase7",
  				"testCase1","testCase2","testCase3","testCase4","testCase5","testCase6","testCase7",
  				"testCase1","testCase2","testCase3","testCase4","testCase5","testCase6","testCase7",
  				"testCase1","testCase2","testCase3","testCase4","testCase5","testCase6","testCase7",
  				"testCase1","testCase2","testCase3","testCase4","testCase5","testCase6","testCase7",
  				"testCase1","testCase2","testCase3","testCase4","testCase5","testCase6","testCase7"
  				],
  		message = null,
  		state = "testCase4";

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Switch
switch (state) {
		case "testCase1":
		  	message = "Test Case 1";
		  	break;
		case "testCase2":
			message = "Test Case 2";
		  	break;
		case "testCase3":
			message = "Test Case 3";
		  	break;
		case "testCase4":
			message = "Test Case 4";
		  	break;
		case "testCase5":
			message = "Test Case 5";
		  	break;
		case "testCase6":
			message = "Test Case 6";
		  	break;
		case "testCase7":
			message = "Test Case 7";
		  	break;
		default:
			message = "Test Case Default";
		  	break;
	}
pending…
Hashtable
var conditions = {
		testCase1 : function() {
			message = "Test Case 1";
		},
		testCase2 : function() {
			message = "Test Case 2";
		},
		testCase3 : function() {
			message = "Test Case 3";
		},
		testCase4 : function() {
			message = "Test Case 4";
		},
		testCase5 : function() {
			message = "Test Case 5";
		},
		testCase6 : function() {
			message = "Test Case 6";
		},
		testCase7 : function() {
			message = "Test Case 7";
		}
	};

	conditions[state]();
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.

0 Comments