Test name | Executions per second |
---|---|
switch test | 80226.0 Ops/sec |
object test | 73937.1 Ops/sec |
<!--your preparation HTML code goes here-->
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]() }
handle_switch(num)
handle_object(num)