forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype-check.js
52 lines (44 loc) · 1.19 KB
/
type-check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'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 util = common.binding('util');
const types = require('internal/util/types');
const func = { native: util, js: types }[version][`is${type}`];
const arg = args[type][argument];
bench.start();
for (let i = 0; i < n; i++) {
func(arg);
}
bench.end(n);
}