Created
December 15, 2014 23:32
-
-
Save phpnode/c4f218c1a4391c93cce9 to your computer and use it in GitHub Desktop.
node --allow-natives-syntax leaky-args.js
This file contains 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
'use strict'; | |
function leakyArgs (item) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
var total = item; | |
for (var i = 0, length = args.length; i < length; i++) { | |
total += args[i] + (300 * 234 * 234234 * 235 * 23433); | |
} | |
return total; | |
} | |
function noLeakyArgs (item) { | |
var totalArguments = arguments.length, | |
args = new Array(totalArguments - 1), | |
a; | |
for (a = 1; a < totalArguments; a++) { | |
args[a - 1] = arguments[a]; | |
} | |
var total = item; | |
for (var i = 0, length = args.length; i < length; i++) { | |
total += args[i] + (300 * 234 * 234234 * 235 * 23433); | |
} | |
return total; | |
} | |
function printStatus(fn) { | |
switch(%GetOptimizationStatus(fn)) { | |
case 1: console.log("Function is optimized"); break; | |
case 2: console.log("Function is not optimized"); break; | |
case 3: console.log("Function is always optimized"); break; | |
case 4: console.log("Function is never optimized"); break; | |
case 6: console.log("Function is maybe deoptimized"); break; | |
} | |
} | |
leakyArgs(10, 1, 2, 3, 4, 5, 6); | |
%OptimizeFunctionOnNextCall(leakyArgs); | |
leakyArgs(10, 1, 2, 3, 4, 5, 6); | |
console.log('Leaky Args:'); | |
printStatus(leakyArgs); | |
noLeakyArgs(10, 1, 2, 3, 4, 5, 6); | |
%OptimizeFunctionOnNextCall(noLeakyArgs); | |
noLeakyArgs(10, 1, 2, 3, 4, 5, 6); | |
console.log('No Leaky Args:'); | |
printStatus(noLeakyArgs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment