Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
if-else vs switch2
(version: 1)
Comparing performance of:
Switch case vs if-else
Created:
11 months ago
by:
Guest
Jump to the latest result
Tests:
Switch case
const a = 1; switch (a) { case 5: console.log("a is 5"); break; case 4: console.log("a is 4"); break; case 3: console.log("a is 3"); break; case 2: console.log("a is 2"); break; case 1: console.log("a is 1"); break; }
if-else
const a = 1; if (a == 5) { console.log("a is 5"); } else if (a == 4) { console.log("a is 4"); } else if (a == 3) { console.log("a is 4"); } else if (a == 2) { console.log("a is 2"); } else if (a == 1) { console.log("a is 1"); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Switch case
if-else
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 OPR/118.0.0.0
Browser/OS:
Opera 118 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Switch case
517765.4 Ops/sec
if-else
530190.9 Ops/sec
Comments
Confirm delete:
Do you really want to delete benchmark?