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
Test name
Executions per second
switch
44155260.0 Ops/sec
if else
45424228.0 Ops/sec
do while 0
43267916.0 Ops/sec
object
514895264.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]