Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
switch vs if...else
(version: 1)
Benchmark.js
Benchmark of the speed difference between using multiple IF statements and an open-ended IF/ELSE IF.
Comparing performance of:
switch vs if/else if
Created:
17 days ago
by:
Guest
Go to the latest result
Script Preparation code:
var test = 'test4'
Tests:
switch
switch(test) { case 'test1': return 1; case 'test2': return 2; case 'test3': return 3; case 'test4': return 4; case 'test5': return 5; default: return 6; }
if/else if
if (test === 'test1') { return 1; } else if (test === 'test2') { return 2; } else if (test === 'test3') { return 3; } else if (test === 'test4') { return 4; } else if (test === 'test5') { return 5; } else { return 6; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
switch
if/else if
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
17 days ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 26_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) EdgiOS/151.0.4129.96 Version/26.0 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 26 on iOS 26.6.1
View result in a separate tab
Embed
Embed Benchmark Result
switch
895.0M/s
if/else if
843.9M/s
View exact numbers
Test name
Executions per second
✓
switch
895,027,968 Ops/sec
if/else if
843,942,976 Ops/sec
Related benchmarks
JS if/if vs if/else if
JS if/if vs if/or
JS switch vs if/else if
JS if/if vs if/else if vs switch
JS if/if vs if multiple conditions fixed
if-else vs switch4
if else vs switch case vs indexOf 2
if/else vs. small switch
JS switch vs if/else if 1 condition
Comments
Confirm delete:
Do you really want to delete benchmark?