Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Switch true vs if else
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/130.0.0.0 Safari/537.36
Browser:
Chrome 130
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
switch
356127.1 Ops/sec
if else
357896.7 Ops/sec
Script Preparation code:
hi = { 1: 3, 4: 7, 2: 999 }; a=1; b=3;
Tests:
switch
switch (true) { case (a in hi): console.log('wow'); break; default: console.log('nope'); } a = (a>1000) ? 0 : ++a
if else
if (a in hi) { console.log('wow'); } else { console.log('nope'); } a = (a>1000) ? 0 : ++a