Test name | Executions per second |
---|---|
Switch | 92319.4 Ops/sec |
Object Literal | 84619.3 Ops/sec |
var str = 'abc';
str = str.charAt(Math.floor(Math.random() * 3));
switch (str) {
case 'a': console.log('A'); break;
case 'b': console.log('B'); break;
case 'c': console.log('C'); break;
}
const a = () => console.log('A')
const b = () => console.log('B')
const c = () => console.log('C')
const objLiteral = {
a: a,
b: b,
c: c
}
objLiteral[str]();