Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
switch vs object literal benchmark
switch vs object literal benchmark
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser:
Chrome 123
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
switch test
80226.0 Ops/sec
object test
73937.1 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var str = 'abc'; str = str.charAt(Math.floor(Math.random() * 3)); var num = str.charCodeAt(0) const a = 'a'.charCodeAt(0) const b = 'b'.charCodeAt(0) const c = 'c'.charCodeAt(0) function handle_switch (num) { switch (num) { case 97: console.log('A'); break; case 98: console.log('B'); break; case 99: console.log('C'); break; } } const object = { 97: function () { console.log('A') }, 98: function () { console.log('B') }, 99: function () { console.log('C') } } function handle_object (num) { object[num]() }
Tests:
switch test
handle_switch(num)
object test
handle_object(num)