switch vs object literal vs module (v7)

Revision 7 of this benchmark created on


Preparation HTML

<script>
  // called by switch 
  var alpha = function() {
   return true;
  };
  // alternatives to switch
  var switchObj = {
   0x01: alpha
  },
  switchModule = (function() {
    return {
     0x01: alpha
    };
   })();
  
  // test var
  var foo = 0x01;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
switch
switch (foo) {
case 0x01:
 alpha();
 break;
default:
 // something to default to
 break;
}
ready
object literal
switchObj[foo]();
ready
module
switchModule[foo]();
ready

Revisions

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