Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Switch vs Object Literal (loop version)
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Android 14; Mobile; rv:143.0) Gecko/143.0 Firefox/143.0
Browser:
Firefox Mobile 143
Operating system:
Android
Device Platform:
Mobile
Date tested:
8 months ago
Test name
Executions per second
Switch
138187424.0 Ops/sec
Object Literal
647985920.0 Ops/sec
Script Preparation code:
var str = 'abc'; str = str.charAt(Math.floor(Math.random() * 3));
Tests:
Switch
for (let i = 0; i++; i < 10000) { switch (str) { case 'a': console.log('A'); break; case 'b': console.log('B'); break; case 'c': console.log('C'); break; } }
Object Literal
const objLiteral = { a: function() { console.log('A'); }, b: function() { console.log('B'); }, c: function() { console.log('C'); } } for (let i = 0; i++; i < 10000) { objLiteral[str](); }