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 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0
Browser:
Firefox 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
object
514.9M/s
if else
45.4M/s
switch
44.2M/s
do while 0
43.3M/s
View exact numbers
Test name
Executions per second
✓
object
514,895,264 Ops/sec
if else
45,424,228 Ops/sec
switch
44,155,260 Ops/sec
do while 0
43,267,916 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]