Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Switch vs Object Literal defined once
(version: 0)
Comparing performance of:
Switch vs Object Literal
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var str = 'abc'; str = str.charAt(Math.floor(Math.random() * 3)); var objLiteral = { a: function() { console.log('A'); }, b: function() { console.log('B'); }, c: function() { console.log('C'); } }
Tests:
Switch
switch (str) { case 'a': console.log('A'); break; case 'b': console.log('B'); break; case 'c': console.log('C'); break; }
Object Literal
objLiteral[str]();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Switch
Object Literal
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Object.assign vs mutation assign
Object speard vs assign
Create object
Object.assign mutation vs spread
Switch/case vs indexOf
Comments
Confirm delete:
Do you really want to delete benchmark?