If-else vs. switch vs. lookup table (v56)

Revision 56 of this benchmark created by Aaron T on


Setup

function ifElseTest(stuff) {
      if(stuff === "pizza") {
        return "food";
      }
    };
    
    function switchTest(stuff) {
      switch (stuff) {
        case "pizza":
          return "food";
        break;
      }
    };

Test runner

Ready to run.

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

Revisions

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