Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser:
Chrome 129
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Switch
384978.8 Ops/sec
Object Literal
387697.5 Ops/sec
Array Literal
379344.8 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)]();