mirror of https://github.com/nodejs/node.git
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
parent
eeb2c8fcbb
commit
ff8db70bc2
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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 '':
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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}`];
|
||||
|
|
Loading…
Reference in New Issue