benchmark: add common.binding()

Recently, process.binding() was replaced with internalBinding().
However, internalBinding() is not available on older builds of
Node, which are often used for benchmarking purposes. This commit
adds a common.binding() to the benchmarks to work around the
issue. Hopefully, this can be removed in the not too distant
future.

PR-URL: https://github.com/nodejs/node/pull/23460
Fixes: https://github.com/nodejs/node/issues/23436
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
pull/23460/head
cjihrig 2018-10-12 12:45:26 -04:00
parent eeb2c8fcbb
commit ff8db70bc2
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
8 changed files with 33 additions and 21 deletions

View File

@ -242,3 +242,13 @@ Benchmark.prototype.report = function(rate, elapsed) {
type: 'report'
});
};
exports.binding = function(bindingName) {
try {
const { internalBinding } = require('internal/test/binding');
return internalBinding(bindingName);
} catch {
return process.binding(bindingName);
}
};

View File

@ -10,8 +10,7 @@ const bench = common.createBenchmark(main, {
});
function main({ len, n }) {
const { internalBinding } = require('internal/test/binding');
const { HTTPParser } = internalBinding('http_parser');
const { HTTPParser } = common.binding('http_parser');
const REQUEST = HTTPParser.REQUEST;
const kOnHeaders = HTTPParser.kOnHeaders | 0;
const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;

View File

@ -3,7 +3,7 @@
const common = require('../common.js');
let icu;
try {
icu = process.binding('icu');
icu = common.binding('icu');
} catch (err) {}
const punycode = require('punycode');

View File

@ -11,7 +11,7 @@ const bench = common.createBenchmark(main, {
const {
TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent
} = process.binding('constants').trace;
} = common.binding('constants').trace;
function doTrace(n, trace) {
bench.start();
@ -31,12 +31,10 @@ function doIsTraceCategoryEnabled(n, isTraceCategoryEnabled) {
}
function main({ n, method }) {
const { internalBinding } = require('internal/test/binding');
const {
trace,
isTraceCategoryEnabled
} = internalBinding('trace_events');
} = common.binding('trace_events');
switch (method) {
case '':

View File

@ -15,10 +15,12 @@ const bench = common.createBenchmark(main, {
}, { flags: [ '--expose-internals', '--no-warnings' ] });
function main({ dur, len, type }) {
const { internalBinding } = require('internal/test/binding');
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
const { TCPConnectWrap } = process.binding('tcp_wrap');
const { WriteWrap } = internalBinding('stream_wrap');
const {
TCP,
TCPConnectWrap,
constants: TCPConstants
} = common.binding('tcp_wrap');
const { WriteWrap } = common.binding('stream_wrap');
const PORT = common.PORT;
const serverHandle = new TCP(TCPConstants.SERVER);

View File

@ -17,10 +17,12 @@ const bench = common.createBenchmark(main, {
});
function main({ dur, len, type }) {
const { internalBinding } = require('internal/test/binding');
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
const { TCPConnectWrap } = process.binding('tcp_wrap');
const { WriteWrap } = internalBinding('stream_wrap');
const {
TCP,
TCPConnectWrap,
constants: TCPConstants
} = common.binding('tcp_wrap');
const { WriteWrap } = common.binding('stream_wrap');
const PORT = common.PORT;
function fail(err, syscall) {

View File

@ -17,10 +17,12 @@ const bench = common.createBenchmark(main, {
});
function main({ dur, len, type }) {
const { internalBinding } = require('internal/test/binding');
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
const { TCPConnectWrap } = process.binding('tcp_wrap');
const { WriteWrap } = internalBinding('stream_wrap');
const {
TCP,
TCPConnectWrap,
constants: TCPConstants
} = common.binding('tcp_wrap');
const { WriteWrap } = common.binding('stream_wrap');
const PORT = common.PORT;
const serverHandle = new TCP(TCPConstants.SERVER);

View File

@ -38,8 +38,7 @@ function main({ type, argument, version, n }) {
// For testing, if supplied with an empty type, default to ArrayBufferView.
type = type || 'ArrayBufferView';
const { internalBinding } = require('internal/test/binding');
const util = internalBinding('util');
const util = common.binding('util');
const types = require('internal/util/types');
const func = { native: util, js: types }[version][`is${type}`];