node/benchmark/util/type-check.js
Ruben Bridgewater de33a5aa6e
benchmark: refactor util benchmarks
This significantly reduces the benchmark runtime. It removes to many
variations that do not provide any benefit and reduces the iterations.

PR-URL: https://github.com/nodejs/node/pull/22503
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
2018-09-07 19:58:36 +02:00

54 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
const arrayBuffer = new ArrayBuffer();
const dataView = new DataView(arrayBuffer);
const uint8Array = new Uint8Array(arrayBuffer);
const int32Array = new Int32Array(arrayBuffer);
const args = {
ArrayBufferView: {
'true': dataView,
'false-primitive': true,
'false-object': arrayBuffer
},
TypedArray: {
'true': int32Array,
'false-primitive': true,
'false-object': arrayBuffer
},
Uint8Array: {
'true': uint8Array,
'false-primitive': true,
'false-object': int32Array
}
};
const bench = common.createBenchmark(main, {
type: Object.keys(args),
version: ['native', 'js'],
argument: ['true', 'false-primitive', 'false-object'],
n: [1e5]
}, {
flags: ['--expose-internals']
});
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 types = require('internal/util/types');
const func = { native: util, js: types }[version][`is${type}`];
const arg = args[type][argument];
bench.start();
for (var i = 0; i < n; i++) {
func(arg);
}
bench.end(n);
}