Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Switch vs Object Literal w/out console.log 4
(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 = 'abcdef'; str = str.charAt(Math.floor(Math.random() * 6)); function fn1() {return 'one'}; function fn2() {return 'two'}; function fn3() {return 'three'}; function switchFn(s) { switch (s) { case 'a': return fn1(); case 'b': return fn2(); case 'c': return fn3(); case 'd': return fn1(); case 'e': return fn2(); case 'f': return fn3(); } }
Tests:
Switch
switchFn(str);
Object Literal
var objLiteral = { a: fn1, b: fn2, c: fn3, d: fn1, e: fn2, f: fn3 }; 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:
Switch vs Object Literal w/out console.log 2
Switch vs Object Literal w/out console.log 3
Switch vs Object Literal (fixed prep code)
Switch vs Object Literal extended
Comments
Confirm delete:
Do you really want to delete benchmark?