标签:default i++ efault === cas 简单 time 总结 const
当我们使用js作值比较的时候,往往会想到是用if还是用switch?
下面简单做一下比较
const tem = 2;
console.time(‘if‘);
for (let i = 0; i < 50000; i++) {
if (tem === 1) {
} else if (tem === 2){
} else {
}
}
console.timeEnd(‘if‘); // if: 2.204ms
console.time(‘switch‘);
for (let j = 0; j < 50000; j++) {
switch (tem) {
case 1:
break;
case 2:
break;
default:
break;
}
}
console.timeEnd(‘switch‘); // switch: 1.386ms
标签:default i++ efault === cas 简单 time 总结 const
原文地址:https://www.cnblogs.com/xpengp/p/12800332.html