0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/misc/trace.js
cjihrig ff8db70bc2
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>
2018-10-14 13:23:16 -04:00

51 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
n: [100000],
method: ['trace', 'isTraceCategoryEnabled']
}, {
flags: ['--expose-internals', '--trace-event-categories', 'foo']
});
const {
TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent
} = common.binding('constants').trace;
function doTrace(n, trace) {
bench.start();
for (var i = 0; i < n; i++) {
trace(kBeforeEvent, 'foo', 'test', 0, 'test');
}
bench.end(n);
}
function doIsTraceCategoryEnabled(n, isTraceCategoryEnabled) {
bench.start();
for (var i = 0; i < n; i++) {
isTraceCategoryEnabled('foo');
isTraceCategoryEnabled('bar');
}
bench.end(n);
}
function main({ n, method }) {
const {
trace,
isTraceCategoryEnabled
} = common.binding('trace_events');
switch (method) {
case '':
case 'trace':
doTrace(n, trace);
break;
case 'isTraceCategoryEnabled':
doIsTraceCategoryEnabled(n, isTraceCategoryEnabled);
break;
default:
throw new Error(`Unexpected method "${method}"`);
}
}