Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
if/else vs. small switch
(version: 1)
Comparing performance of:
switch vs if/else
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
const a = 1; let b;
Tests:
switch
switch(a) { case 0: b = 1; break; case 1: b = 2; break; default: b = 3; }
if/else
if (a === 0) { b = 1; } else if (a === 1) { b = 2; } else { b = 3; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
switch
if/else
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0
Browser/OS:
Chrome 144 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
switch
5665185.5 Ops/sec
if/else
5671076.0 Ops/sec
Related benchmarks:
switch vs if
switch vs if
switch vs if
Switch true vs if else
my test bench 1
if-else vs switch 2
if/switch1
if-else vs switch4
if else vs switch case vs indexOf 2
Comments
Confirm delete:
Do you really want to delete benchmark?