Created
April 29, 2016 03:00
-
-
Save fengmk2/adad365d273d5dd33df6423262ba22cd to your computer and use it in GitHub Desktop.
optimized-test.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'; | |
// http://dev.zm1v1.com/2015/08/19/javascript-optimization-killers/?spm=0.0.0.0.Rxyzi2 | |
function testFn(a, b) { | |
const c = (a || 0) + (b || 1); | |
return c; | |
} | |
function printStatus(fn) { | |
var status = %GetOptimizationStatus(fn); | |
switch(status) { | |
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; | |
default: console.log("Unknow GetOptimizationStatus %s", status); break; | |
} | |
} | |
console.log('node %s', process.version); | |
console.log(testFn.toString()); | |
testFn(); | |
testFn(); | |
%OptimizeFunctionOnNextCall(testFn); | |
testFn(); | |
printStatus(testFn); | |
// $ node --trace_opt --trace_deopt --allow-natives-syntax optimized-test.js |
Author
fengmk2
commented
Apr 29, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment