Skip to content

Commit

Permalink
benchmark: add common.binding()
Browse files Browse the repository at this point in the history
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: #23460
Fixes: #23436
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
cjihrig committed Oct 14, 2018
1 parent eeb2c8f commit ff8db70
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 21 deletions.
10 changes: 10 additions & 0 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
3 changes: 1 addition & 2 deletions benchmark/http/bench-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/misc/punycode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
6 changes: 2 additions & 4 deletions benchmark/misc/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 '':
Expand Down
10 changes: 6 additions & 4 deletions benchmark/net/tcp-raw-c2s.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions benchmark/net/tcp-raw-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions benchmark/net/tcp-raw-s2c.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions benchmark/util/type-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`];
Expand Down

0 comments on commit ff8db70

Please sign in to comment.