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 (Android 6.0.1; Mobile; rv:127.0) Gecko/127.0 Firefox/127.0
Browser:
Firefox Mobile 127
Operating system:
Android 6.0.1
Device Platform:
Mobile
Date tested:
one year ago
Test name
Executions per second
Switch
5368.1 Ops/sec
Object Literal
5222.4 Ops/sec
Array Literal
4959.2 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)]();