Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
if-else vs object 3
(version: 0)
Comparing performance of:
object vs if-else
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
class Host { A = 1; B = 2; C = 3; } var host = new Host(); var x = Math.floor(Math.random() * 3); function testObject(h, p) { const obj = { [h.A]: 1, [h.B]: 2, [h.C]: 3, } return obj[p]; } function testIfElse(h, p) { var v = 0; if (p === h.A) { v = 1; } else if (p === h.B) { v = 2; } else if (p === h.C) { v = 3; } return v; }
Tests:
object
testObject(host, x);
if-else
testIfElse(host, x);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
object
if-else
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.keys() vs _.key()
Create object
Spread vs Object.assign (modify ) vs Object.assign (new)
off arrays function
Object spread
Comments
Confirm delete:
Do you really want to delete benchmark?