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
Test name
Executions per second
switch
16338544.0 Ops/sec
if else
4373649.5 Ops/sec
do while 0
4370581.5 Ops/sec
object
16349788.0 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]