1'use strict'; 2 3const common = require('../common'); 4 5const arrayBuffer = new ArrayBuffer(); 6const dataView = new DataView(arrayBuffer); 7const uint8Array = new Uint8Array(arrayBuffer); 8const int32Array = new Int32Array(arrayBuffer); 9 10const args = { 11 ArrayBufferView: { 12 'true': dataView, 13 'false-primitive': true, 14 'false-object': arrayBuffer, 15 }, 16 TypedArray: { 17 'true': int32Array, 18 'false-primitive': true, 19 'false-object': arrayBuffer, 20 }, 21 Uint8Array: { 22 'true': uint8Array, 23 'false-primitive': true, 24 'false-object': int32Array, 25 }, 26}; 27 28const bench = common.createBenchmark(main, { 29 type: Object.keys(args), 30 version: ['native', 'js'], 31 argument: ['true', 'false-primitive', 'false-object'], 32 n: [1e5], 33}, { 34 flags: ['--expose-internals', '--no-warnings'], 35}); 36 37function main({ type, argument, version, n }) { 38 const util = common.binding('util'); 39 const types = require('internal/util/types'); 40 41 const func = { native: util, js: types }[version][`is${type}`]; 42 const arg = args[type][argument]; 43 44 bench.start(); 45 for (let i = 0; i < n; i++) { 46 func(arg); 47 } 48 bench.end(n); 49} 50