Skip to content

Commit 962c1e1

Browse files
committed
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: #6222 Reviewed-By: Brian White <mscdex@mscdex.net>
1 parent 77e2efe commit 962c1e1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

benchmark/common.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,15 @@ Benchmark.prototype.getHeading = function() {
255255
}).join(',');
256256
}
257257
};
258+
259+
exports.v8ForceOptimization = function(method, ...args) {
260+
if (typeof method !== 'function')
261+
return;
262+
const v8 = require('v8');
263+
v8.setFlagsFromString('--allow_natives_syntax');
264+
method.apply(null, args);
265+
eval('%OptimizeFunctionOnNextCall(method)');
266+
method.apply(null, args);
267+
return eval('%GetOptimizationStatus(method)');
268+
};
269+

0 commit comments

Comments
 (0)