// 循环
function forLoop() {
console.time(‘forloop’)
for(var i = 0; i < 100001; i++) {
console.log(i)
if (i >= 100000) {
console.timeEnd(‘forloop’)
}
}
}
forloop: 3458.93994140625 ms
// 递归
var i = 0;
function down () {
if (i === 0) {
console.time(‘downs’)
}
console.log(i)
if (i < 100000) {
i++
down()
} else {
console.timeEnd('downs')
}
}
VM7843:4 Uncaught RangeError: Maximum call stack size exceeded
at down (:4:5)
at down (:10:9)
at down (:10:9)
at down (:10:9)
at down (:10:9)
at down (:10:9)
at down (:10:9)
at down (:10:9)
at down (:10:9)
at down (:10:9)
栈溢出