Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
Switch vs Prepared Object Literal vs Prepared Array
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser:
Chrome 130
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Benchmark engine:
Benchmark.js
Object Literal
138K/s
Array Literal
133K/s
Switch
68K/s
View exact numbers
Test name
Executions per second
✓
Object Literal
138,008 Ops/sec
Array Literal
132,758 Ops/sec
Switch
67,900 Ops/sec
Script Preparation code:
var objLiteral = { 0: function() { console.log('A'); }, 1: function() { console.log('B'); }, 2: function() { console.log('C'); } } var arrayLiteral = [ function() { console.log('A'); }, function() { console.log('B'); }, function() { console.log('C'); } ]; function usingSwitch(c) { switch (c) { case 0: console.log('A'); break; case 1: console.log('B'); break; case 2: console.log('C'); break; } }
Tests:
Switch
usingSwitch(Math.floor(Math.random() * 3))
Object Literal
objLiteral[Math.floor(Math.random() * 3)]();
Array Literal
arrayLiteral[Math.floor(Math.random() * 3)]();