Created
July 9, 2019 15:29
-
-
Save christianscott/a14eb8743d1c6789a78b2879e9655dd6 to your computer and use it in GitHub Desktop.
Measure the maximum stack size for functions with different numbers of arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let range = length => Array.from({ length }, (_, i) => i) | |
let template = (params, args) => `let calls = 0 | |
let r = (${params}) => { | |
calls++ | |
r(${args}) | |
} | |
try { | |
r(${args}) | |
} catch (_) { | |
console.log(calls) | |
}` | |
for (let i = 0; i < 100; i++) { | |
let rendered = template( | |
range(i).map(n => `a${n}`).join(', '), | |
range(i).map(() => `0`).join(', '), | |
) | |
eval(rendered) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment