Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Map vs switch soh
Whats faster a map or a switch statement???
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0
Browser:
Chrome 137
Operating system:
Windows
Device Platform:
Desktop
Date tested:
10 months ago
Test name
Executions per second
Map
178672800.0 Ops/sec
Switch
71022816.0 Ops/sec
Script Preparation code:
const map = { one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9, ten: 10, } function byMap(val) { return map[val] } function bySwitch(val) { switch (val) { case 'one': return 1; case 'two': return 2; case 'three': return 3; case 'four': return 4; case 'five': return 5 case 'six': return 6 case 'seven': return 7 case 'eight': return 8 case 'nine': return 9 case 'ten': return 10 } }
Tests:
Map
byMap('one') byMap('two') byMap('three') byMap('four') byMap('five') byMap('six') byMap('seven') byMap('eight') byMap('nine') byMap('ten')
Switch
bySwitch('one') bySwitch('two') bySwitch('three') bySwitch('four') bySwitch('five') bySwitch('six') bySwitch('seven') bySwitch('eight') bySwitch('nine') bySwitch('ten')