Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
switch vs if else vs do while vs object
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
object
16.3M/s
switch
16.3M/s
if else
4.4M/s
do while 0
4.4M/s
View exact numbers
Test name
Executions per second
✓
object
16,349,788 Ops/sec
switch
16,338,544 Ops/sec
if else
4,373,650 Ops/sec
do while 0
4,370,582 Ops/sec
Script Preparation code:
var a = 'yhahaha';
Tests:
switch
var b; switch(a) { case 'ahaha': b = 1; break; case 'ohoho': b = 2; break; case 'ihihi': b = 3; break; case 'yhahaha': b = 4; break; }
if else
var b; if (a === 'ahaha') { b = 1; } else if (a === 'ohoho') { b = 2; } else if (a === 'ihihi') { b = 3; } else if (a === 'yhahaha') { b = 4; }
do while 0
var b; do { if (a === 'ahaha') { b = 1; break; } if (a === 'ohoho') { b = 2; break; } if (a === 'ihihi') { b = 3; break; } if (a === 'yhahaha') { b = 4; } } while(0)
object
var b = { ahaha: 1, ohoho: 2, ihihi: 3, yhahaha: 4, }[a]