Switch vs Map Lookup

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Switch Lookup
const value = ["Hello", "hi", "bye", "foo"][Math.floor(Math.random() * (4))];

switch (value.toLowerCase()) {
  case "hello":
    return "hello";
    break;
  case "hi":
    return "hi";
    break;
  case "bye":
    return "bye";
    break;
  case "foo":
    return "bar";
    break;
}
ready
Map Lookup
const value = ["Hello", "hi", "bye", "foo"][Math.floor(Math.random() * (4))];

const LOOKUP = {
  "hello": "hello",
  "hi": "hi",
  "bye": "bye",
  "foo": "bar",
};

LOOKUP[value.toLowerCase()];
ready

Revisions

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