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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
switch case
43.2 Ops/sec
jump table
31.6 Ops/sec
jump table (arrow functions)
33.6 Ops/sec
jump table (Map)
32.6 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++) { } }