Skip to content

Instantly share code, notes, and snippets.

@zerobias
Created June 29, 2017 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerobias/1e910d8f51674bcc67473613c1886da6 to your computer and use it in GitHub Desktop.
Save zerobias/1e910d8f51674bcc67473613c1886da6 to your computer and use it in GitHub Desktop.
Tail call optinisation detection and call stack depth counter
let TCO_ENABLED
let stackDepth = 0
try {
(function foo(x){
stackDepth+=1
if (x < 5E5) return foo( x + 1 )
})( 1 )
TCO_ENABLED = true
}
catch (err) {
TCO_ENABLED = false
}
console.log('TCO', TCO_ENABLED, stackDepth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment