diff options
author | Timothy Gu <timothygu99@gmail.com> | 2017-09-28 21:32:47 +0300 |
---|---|---|
committer | Evan Lucas <evanlucas@me.com> | 2017-10-23 17:10:04 +0300 |
commit | b1a68f52e2172b565f5f4d8f08c65a45c023dbf3 (patch) | |
tree | a5e609333c9d4b822d69cbf65ff0c02f02bb2285 /benchmark | |
parent | 67aed7972de5c5e271fd52c2a0e040c5290ec526 (diff) |
benchmark: add util/type-check
Backport-PR-URL: https://github.com/nodejs/node/pull/16073
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>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/util/type-check.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/benchmark/util/type-check.js b/benchmark/util/type-check.js new file mode 100644 index 00000000000..c7e3de7de9f --- /dev/null +++ b/benchmark/util/type-check.js @@ -0,0 +1,44 @@ +'use strict'; + +const common = require('../common'); + +const arrayBuffer = new ArrayBuffer(); +const uint8Array = new Uint8Array(arrayBuffer); +const int32Array = new Int32Array(arrayBuffer); + +const args = { + 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); +} |