Skip to content

Instantly share code, notes, and snippets.

@christianscott
Created July 9, 2019 15:29
Show Gist options
  • Save christianscott/a14eb8743d1c6789a78b2879e9655dd6 to your computer and use it in GitHub Desktop.
Save christianscott/a14eb8743d1c6789a78b2879e9655dd6 to your computer and use it in GitHub Desktop.
Measure the maximum stack size for functions with different numbers of arguments
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