Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
switch case vs object literal abublebublbebubleblelb
(version: 0)
Comparing performance of:
switch vs Object literal
Created:
one year 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:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser/OS:
Chrome 129 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
switch
149698.9 Ops/sec
Object literal
130976.8 Ops/sec
Related benchmarks:
Switch vs Object Literal1551511551
Switch vs Object Literal defined once
Switch vs Object Literal Fixed
Object Literal vs Switch
Switch vs Object Literal (fixed prep code)
Switch vs Object Literal 24r34rf3rr
Object lookup vs switch statement
Comments
Confirm delete:
Do you really want to delete benchmark?