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 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0
Browser:
Firefox 126
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
Array Literal
65K/s
Object Literal
65K/s
Switch
59K/s
View exact numbers
Test name
Executions per second
✓
Array Literal
65,043 Ops/sec
Object Literal
64,661 Ops/sec
Switch
59,254 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)]();