gpt4 book ai didi

javascript - 在 PhantomJS 中,函数调用堆栈限制是多少?

转载 作者:行者123 更新时间:2023-11-30 12:13:45 25 4
gpt4 key购买 nike

在突破 PhantomJS javascript 引擎的调用堆栈限制之前,函数可以递归调用多少次?换句话说,这里为 PhantomJS 打印的最后一个可能的 n 是什么:

var n = 0;
function f() {
console.log(++n);
f();
}
f();

最佳答案

我已经使用了您的代码,并在我的 PC 和运行 Raspbian 的 Raspberry Pi 1 上以不同的 PhantomJS 版本运行了它。

Platform | Version | Maximum callstack--------------------------------------Win 8.1  | 2.0.0   | 65277Win 8.1  | 1.9.8   | 65534Win 8.1  | 1.9.7   | 65534Win 8.1  | 1.9.0   | 65534Win 8.1  | 1.8.2   | 65534RPi 1    | 2.0.1*  | 43547RPi 1    | 1.9.7   | 65534RPi 1    | 1.9.0   | 65534

* Development version compiled on March 13 2015 on a Raspberry Pi 2

The following is a more realistic code example, because you're rarely using synchronous and recursive code in a PhantomJS script or on the page.

var n = 0;
function f() {
console.log(++n);
//f();
setTimeout(f, 0);
}
f();

这个更可能被使用的异步版本没有明显的调用堆栈限制。在大约 300,000 次迭代(52 分钟)后,我停止了该过程(Win 8.1 上的 v1.9.8 和 v2.0.0)。 1.9.8 版一直占用 27.2 MB 内存,而 v2.0.0 则在 8 到 10 MB 内存范围内跳跃。

关于javascript - 在 PhantomJS 中,函数调用堆栈限制是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33016492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com