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 (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
Benchmark engine:
Benchmark.js
switch case
399/s
jump table (arrow functions)
106/s
jump table
100/s
jump table (Map)
88/s
View exact numbers
Test name
Executions per second
✓
switch case
399 Ops/sec
jump table (arrow functions)
106 Ops/sec
jump table
100 Ops/sec
jump table (Map)
88 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++) { } }