switch vs object literal vs module (v18)

Revision 18 of this benchmark created on


Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
switch
switch (foo) {

case "alpha":

 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.