If vs. switch (v46)

Revision 46 of this benchmark created on


Setup

function ifElseTest(stuff) {
      var returnStuff = "";
      if(stuff === "pizza") {
        returnStuff = "food";
      } else if (stuff === "car") {
        returnStuff = "driving";
      }
      return returnStuff;
    };
    
    function switchTest(stuff) {
      var returnStuff = "";
      switch (stuff) {
        case "pizza":
          returnStuff = "food";
          break;
        case "car":
          returnStuff = "driving";
          break;
      }
      return returnStuff;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
if else
ifElseTest("pizza");
ifElseTest("water");
ifElseTest("car");
ready
switch
switchTest("pizza");
switchTest("water");
switchTest("car");
ready

Revisions

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