Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
switch vs if benchmark
is switch faster than if
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36
Browser:
Chrome 151
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
15 days ago
Benchmark engine:
Benchmark.js
switch
601.1M/s
if
38.4M/s
View exact numbers
Test name
Executions per second
✓
switch
601,148,544 Ops/sec
if
38,444,792 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const THRESHOLD_50 = 50; const THRESHOLD_20 = 20; const THRESHOLD_10 = 10; const THRESHOLD_0 = 0; function getThresholdBandSwtich (remaining){ switch (true) { case remaining <= THRESHOLD_0: return THRESHOLD_0; case remaining <= THRESHOLD_10: return THRESHOLD_10; case remaining <= THRESHOLD_20: return THRESHOLD_10; case remaining <= THRESHOLD_50: return THRESHOLD_10; default: return null; } }; function getThresholdBandIf (remaining) { if (remaining <= THRESHOLD_0) return THRESHOLD_0; if (remaining <= THRESHOLD_10) return THRESHOLD_10; if (remaining <= THRESHOLD_20) return THRESHOLD_20; if (remaining <= THRESHOLD_50) return THRESHOLD_50; return null; };
Tests:
switch
getThresholdBandSwtich(50)
if
getThresholdBandIf(50)