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>
This commit is contained in:
parent
eeb2c8fcbb
commit
ff8db70bc2
@ -242,3 +242,13 @@ Benchmark.prototype.report = function(rate, elapsed) {
|
|||||||
type: 'report'
|
type: 'report'
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.binding = function(bindingName) {
|
||||||
|
try {
|
||||||
|
const { internalBinding } = require('internal/test/binding');
|
||||||
|
|
||||||
|
return internalBinding(bindingName);
|
||||||
|
} catch {
|
||||||
|
return process.binding(bindingName);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -10,8 +10,7 @@ const bench = common.createBenchmark(main, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function main({ len, n }) {
|
function main({ len, n }) {
|
||||||
const { internalBinding } = require('internal/test/binding');
|
const { HTTPParser } = common.binding('http_parser');
|
||||||
const { HTTPParser } = internalBinding('http_parser');
|
|
||||||
const REQUEST = HTTPParser.REQUEST;
|
const REQUEST = HTTPParser.REQUEST;
|
||||||
const kOnHeaders = HTTPParser.kOnHeaders | 0;
|
const kOnHeaders = HTTPParser.kOnHeaders | 0;
|
||||||
const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
|
const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
const common = require('../common.js');
|
const common = require('../common.js');
|
||||||
let icu;
|
let icu;
|
||||||
try {
|
try {
|
||||||
icu = process.binding('icu');
|
icu = common.binding('icu');
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
const punycode = require('punycode');
|
const punycode = require('punycode');
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ const bench = common.createBenchmark(main, {
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent
|
TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent
|
||||||
} = process.binding('constants').trace;
|
} = common.binding('constants').trace;
|
||||||
|
|
||||||
function doTrace(n, trace) {
|
function doTrace(n, trace) {
|
||||||
bench.start();
|
bench.start();
|
||||||
@ -31,12 +31,10 @@ function doIsTraceCategoryEnabled(n, isTraceCategoryEnabled) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function main({ n, method }) {
|
function main({ n, method }) {
|
||||||
const { internalBinding } = require('internal/test/binding');
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
trace,
|
trace,
|
||||||
isTraceCategoryEnabled
|
isTraceCategoryEnabled
|
||||||
} = internalBinding('trace_events');
|
} = common.binding('trace_events');
|
||||||
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case '':
|
case '':
|
||||||
|
@ -15,10 +15,12 @@ const bench = common.createBenchmark(main, {
|
|||||||
}, { flags: [ '--expose-internals', '--no-warnings' ] });
|
}, { flags: [ '--expose-internals', '--no-warnings' ] });
|
||||||
|
|
||||||
function main({ dur, len, type }) {
|
function main({ dur, len, type }) {
|
||||||
const { internalBinding } = require('internal/test/binding');
|
const {
|
||||||
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
TCP,
|
||||||
const { TCPConnectWrap } = process.binding('tcp_wrap');
|
TCPConnectWrap,
|
||||||
const { WriteWrap } = internalBinding('stream_wrap');
|
constants: TCPConstants
|
||||||
|
} = common.binding('tcp_wrap');
|
||||||
|
const { WriteWrap } = common.binding('stream_wrap');
|
||||||
const PORT = common.PORT;
|
const PORT = common.PORT;
|
||||||
|
|
||||||
const serverHandle = new TCP(TCPConstants.SERVER);
|
const serverHandle = new TCP(TCPConstants.SERVER);
|
||||||
|
@ -17,10 +17,12 @@ const bench = common.createBenchmark(main, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function main({ dur, len, type }) {
|
function main({ dur, len, type }) {
|
||||||
const { internalBinding } = require('internal/test/binding');
|
const {
|
||||||
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
TCP,
|
||||||
const { TCPConnectWrap } = process.binding('tcp_wrap');
|
TCPConnectWrap,
|
||||||
const { WriteWrap } = internalBinding('stream_wrap');
|
constants: TCPConstants
|
||||||
|
} = common.binding('tcp_wrap');
|
||||||
|
const { WriteWrap } = common.binding('stream_wrap');
|
||||||
const PORT = common.PORT;
|
const PORT = common.PORT;
|
||||||
|
|
||||||
function fail(err, syscall) {
|
function fail(err, syscall) {
|
||||||
|
@ -17,10 +17,12 @@ const bench = common.createBenchmark(main, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function main({ dur, len, type }) {
|
function main({ dur, len, type }) {
|
||||||
const { internalBinding } = require('internal/test/binding');
|
const {
|
||||||
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
TCP,
|
||||||
const { TCPConnectWrap } = process.binding('tcp_wrap');
|
TCPConnectWrap,
|
||||||
const { WriteWrap } = internalBinding('stream_wrap');
|
constants: TCPConstants
|
||||||
|
} = common.binding('tcp_wrap');
|
||||||
|
const { WriteWrap } = common.binding('stream_wrap');
|
||||||
const PORT = common.PORT;
|
const PORT = common.PORT;
|
||||||
|
|
||||||
const serverHandle = new TCP(TCPConstants.SERVER);
|
const serverHandle = new TCP(TCPConstants.SERVER);
|
||||||
|
@ -38,8 +38,7 @@ function main({ type, argument, version, n }) {
|
|||||||
// For testing, if supplied with an empty type, default to ArrayBufferView.
|
// For testing, if supplied with an empty type, default to ArrayBufferView.
|
||||||
type = type || 'ArrayBufferView';
|
type = type || 'ArrayBufferView';
|
||||||
|
|
||||||
const { internalBinding } = require('internal/test/binding');
|
const util = common.binding('util');
|
||||||
const util = internalBinding('util');
|
|
||||||
const types = require('internal/util/types');
|
const types = require('internal/util/types');
|
||||||
|
|
||||||
const func = { native: util, js: types }[version][`is${type}`];
|
const func = { native: util, js: types }[version][`is${type}`];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user