Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
switch vs if test
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 20
791.9M/s
switch 0
791.9M/s
if 0
789.8M/s
switch 50
789.6M/s
if 20
787.8M/s
if 50
784.9M/s
View exact numbers
Test name
Executions per second
✓
switch 20
791,914,432 Ops/sec
switch 0
791,905,408 Ops/sec
if 0
789,798,272 Ops/sec
switch 50
789,625,600 Ops/sec
if 20
787,803,776 Ops/sec
if 50
784,929,664 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 50
getThresholdBandSwtich(50)
if 50
getThresholdBandIf(50)
switch 0
getThresholdBandSwtich(0)
if 0
getThresholdBandIf(0)
switch 20
getThresholdBandSwtich(20)
if 20
getThresholdBandIf(20)