mirror of https://github.com/lukechilds/node.git
Browse Source
PR-URL: https://github.com/nodejs/node/pull/15663 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>v9.x-staging
Timothy Gu
7 years ago
committed by
Ruben Bridgewater
1 changed files with 50 additions and 0 deletions
@ -0,0 +1,50 @@ |
|||||
|
'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'], |
||||
|
millions: ['5'] |
||||
|
}, { |
||||
|
flags: ['--expose-internals'] |
||||
|
}); |
||||
|
|
||||
|
function main(conf) { |
||||
|
const util = process.binding('util'); |
||||
|
const types = require('internal/util/types'); |
||||
|
|
||||
|
const n = (+conf.millions * 1e6) | 0; |
||||
|
const func = { native: util, js: types }[conf.version][`is${conf.type}`]; |
||||
|
const arg = args[conf.type][conf.argument]; |
||||
|
|
||||
|
bench.start(); |
||||
|
for (var i = 0; i < n; i++) { |
||||
|
func(arg); |
||||
|
} |
||||
|
bench.end(n); |
||||
|
} |
Loading…
Reference in new issue