Skip to content

Instantly share code, notes, and snippets.

@robotlolita
Created November 26, 2013 02:03
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 robotlolita/7652390 to your computer and use it in GitHub Desktop.
Save robotlolita/7652390 to your computer and use it in GitHub Desktop.
function f(a) {
if (a > 1000) return 1
if (a > 100) return 2
if (a > 10) return 3
return 4
}
var i = 100000;
while (i--) {
f(Math.random() * 1000)
}
// $ node --trace-inlining bar-2.js
// Inlining builtin 0x148b0391c829 <JS Function random>
// Inlined f called from .
function f(a) {
if (a > 1000) return 1
if (a > 100) return 2
if (a > 10) return 3
return f
}
var i = 100000;
while (i--) {
f(Math.random() * 1000)
}
// $ node --trace-inlining bar.js
// Inlining builtin 0x31104761c829 <JS Function random>
// Did not inline f called from (target requires context change).
(It apparently does inline if the inconsistent types are primitives/nullables, though)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment