Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
String match in list: switch-case vs. Array.includes() vs. Set.has()
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser:
Chrome 138
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
10 months ago
Test name
Executions per second
switch-case
54491236.0 Ops/sec
Array.includes
8172566.0 Ops/sec
Set.has
62320788.0 Ops/sec
Script Preparation code:
const Module = { A: "mZefJFD9", B: "dLl9J", C: "4oi4VcZlKi", D: "xvtEMvioQ", E: "pDDKU02Rqz", F: "KcyMMfk", G: "Qqu5xOgk", H: "eHnpQ", I: "jvKje3L", J: "YazYS", K: "YN8np", L: "xbcBKzC", M: "6zJY", N: "rrZyuOBlU", O: "JfK19e6", P: "9vMweXIY", Q: "fell3", R: "JbD0176", S: "DwIj", T: "eRgPvoP", U: "d6pM", V: "lVw3HCDBm", W: "ujrM", X: "ih3NJy49pP", Y: "VgLEB3", Z: "jSo12", } function testSwitchCase(s) { switch (s) { case Module.A: case Module.B: case Module.C: case Module.D: case Module.E: case Module.F: case Module.G: case Module.H: case Module.I: case Module.J: case Module.K: case Module.L: case Module.M: case Module.N: case Module.O: case Module.P: case Module.Q: case Module.R: case Module.S: case Module.T: case Module.U: case Module.V: case Module.W: case Module.X: case Module.Y: case Module.Z: return true; } return false; } const array = Object.values(Module) function testArrayIncludes(s) { return array.includes(s); } const set = new Set(array) function testSetHas(s) { return set.has(s); } const testee = [ "none", array[6], "not found", array[13], "???", array[20], ];
Tests:
switch-case
for (const s of testee) { testSwitchCase(s); }
Array.includes
for (const s of testee) { testArrayIncludes(s); }
Set.has
for (const s of testee) { testSetHas(s); }