Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
if-else vs switch and variations
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0
Browser:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
if-else-if-else
67078672.0 Ops/sec
switch-with-default-initialized
69576760.0 Ops/sec
switch-without-default
69345888.0 Ops/sec
Tests:
if-else-if-else
let errorKey = 'error_occured' const err = { status: 503 } if (err.status == 401) { errorKey = 'error_rrn_not_authorized' } else if (err.status == 400 || err.status == 404) { errorKey = 'error_rrn_no_match' } else if (err.status == 502 || err.status == 503) { errorKey = 'error_rrn_not_available' }
switch-with-default-initialized
let errorKey = 'error_occured' const err = { status: 503 } switch (err.status) { case 401: errorKey = 'error_rrn_not_authorized' break case 400: case 404: errorKey = 'error_rrn_no_match' break case 502: case 503: errorKey = 'error_rrn_not_available' break }
switch-without-default
let errorKey const err = { status: 503 } switch (err.status) { case 401: errorKey = 'error_rrn_not_authorized' break case 400: case 404: errorKey = 'error_rrn_no_match' break case 502: case 503: errorKey = 'error_rrn_not_available' break default: errorKey = 'error_occured' }