function f(){
let n = 0
console.time('f')
for (let i = 0; i < 1000000000; i++) {
n += 1
}
console.timeEnd('f')
}
function g(){
let n = 0
console.time('g')
try {
for (let i = 0; i < 1000000000; i++) {
try {
n += 1
}catch(e) {}
}
}catch(e){}
console.timeEnd('g')
}
f();g();
output result
➜ static node -v
v7.9.0
➜ static node test.js
f: 11293.079ms
g: 5800.848ms
➜ static sudo n 6.9.5
➜ static node -v
v6.9.5
➜ static node test.js
f: 9922.718ms
g: 12212.024ms
➜ static
why try catch block faster than normal 2x
is that means we should work with all try?
try everything to get more performance
hope to get the answer
thankx all
via Shinhwe
No comments:
Post a Comment