Test name | Executions per second |
---|---|
dict | 42533.8 Ops/sec |
if | 41561.2 Ops/sec |
switch | 41135.1 Ops/sec |
const dict = {};
dict['test1'] = 'sth1';
dict['test2'] = 'sth2';
dict['test3'] = 'sth3';
let t = 'nn';
console.log(dict[t]);
t='test1';
console.log(dict[t]);
t='test2';
console.log(dict[t]);
t='test3';
console.log(dict[t]);
let t = 'nn';
if(t === 'test1') {
console.log('sth1');
} else if(t == 'test2') {
console.log('sth2');
} else if(t == 'test3') {
console.log('sth3');
} else {
console.log(undefined);
}
t='test1';
if(t === 'test1') {
console.log('sth1');
} else if(t == 'test2') {
console.log('sth2');
} else if(t == 'test3') {
console.log('sth3');
} else {
console.log(undefined);
}
t='test2';
if(t === 'test1') {
console.log('sth1');
} else if(t == 'test2') {
console.log('sth2');
} else if(t == 'test3') {
console.log('sth3');
} else {
console.log(undefined);
}
t='test3';
if(t === 'test1') {
console.log('sth1');
} else if(t == 'test2') {
console.log('sth2');
} else if(t == 'test3') {
console.log('sth3');
} else {
console.log(undefined);
}
let t='nn';
switch(t) {
case 'test1':
console.log('sth1');
break;
case 'test2':
console.log('sth2');
break;
case 'test3':
console.log('sth3');
break;
default:
console.log(undefined);
}
t='test1';
switch(t) {
case 'test1':
console.log('sth1');
break;
case 'test2':
console.log('sth2');
break;
case 'test3':
console.log('sth3');
break;
default:
console.log(undefined);
}
t='test2';
switch(t) {
case 'test1':
console.log('sth1');
break;
case 'test2':
console.log('sth2');
break;
case 'test3':
console.log('sth3');
break;
default:
console.log(undefined);
}
t='test3';
switch(t) {
case 'test1':
console.log('sth1');
break;
case 'test2':
console.log('sth2');
break;
case 'test3':
console.log('sth3');
break;
default:
console.log(undefined);
}