Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
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
Benchmark engine:
Benchmark.js
switch case
43/s
jump table (arrow functions)
34/s
jump table (Map)
33/s
jump table
32/s
View exact numbers
Test name
Executions per second
✓
switch case
43 Ops/sec
jump table (arrow functions)
34 Ops/sec
jump table (Map)
33 Ops/sec
jump table
32 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++) { } }