From cb9eff2f93731b03a7d7138eee3919243a0cfd69 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 15 Apr 2016 13:55:23 -0700 Subject: [PATCH] benchmarks: add common.v8ForceOptimization 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: https://github.com/nodejs/node/pull/6222 Reviewed-By: Brian White --- benchmark/common.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/benchmark/common.js b/benchmark/common.js index d1bc985f092..71b93d038ae 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -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)'); +}; +