Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Jump vs switch case v2
Updated to separate function creation from test. Also added in alternatives for arrow functions and Map
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:138.0) Gecko/20100101 Firefox/138.0
Browser:
Firefox 138
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
switch case
399.4 Ops/sec
jump table
100.0 Ops/sec
jump table (arrow functions)
105.7 Ops/sec
jump table (Map)
88.5 Ops/sec
Script Preparation code:
// Switch function thing(j) { switch(j) { case 0: return "rah"; case 1: return "lah"; case 2: return "sah"; case 3: return "blah"; } } // Jumptable function rah() { return "rah"; } function lah() { return "lah"; } function sah() { return "sah"; } function blah() { return "blah"; } var jumpTable = [rah, lah, sah, blah]; // Arrow functions var jumpTableArrow = [() => "rah", () => "lah", () => "sah", () => "blah"] // Map var jumpTableMap = new Map(jumpTableArrow.map((fun, i) => [i, fun]))
Tests:
switch case
for(let i = 0; i < 100000; i++) { for(let j = 0; thing(j) != "blah"; j++) { } }
jump table
for(let i = 0; i < 100000; i++) { for(let j = 0; jumpTable[j]() != "blah"; j++) { } }
jump table (arrow functions)
for(let i = 0; i < 100000; i++) { for(let j = 0; jumpTableArrow[j]() != "blah"; j++) { } }
jump table (Map)
for(let i = 0; i < 100000; i++) { for(let j = 0; jumpTableMap.get(j)() != "blah"; j++) { } }