Skip to content

Commit

Permalink
benchmarks: add common.v8ForceOptimization
Browse files Browse the repository at this point in the history
It's useful to be able to force optimization of a function.
Rather than duplicating the code everywhere for it, let's
make a utility available.

PR-URL: #6222
Reviewed-By: Brian White <mscdex@mscdex.net>
  • Loading branch information
jasnell committed Apr 26, 2016
1 parent 77e2efe commit 962c1e1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,15 @@ Benchmark.prototype.getHeading = function() {
}).join(',');
}
};

exports.v8ForceOptimization = function(method, ...args) {
if (typeof method !== 'function')
return;
const v8 = require('v8');
v8.setFlagsFromString('--allow_natives_syntax');
method.apply(null, args);
eval('%OptimizeFunctionOnNextCall(method)');
method.apply(null, args);
return eval('%GetOptimizationStatus(method)');
};

0 comments on commit 962c1e1

Please sign in to comment.