Skip to content

Commit

Permalink
tools, benchmark: test util benchmark
Browse files Browse the repository at this point in the history
Create a minimal test for the util benchmark files.

PR-URL: #16050
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
  • Loading branch information
sarahmeyer authored and Trott committed Oct 28, 2017
1 parent 64aded3 commit 50fe1a8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions benchmark/util/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const bench = common.createBenchmark(main, {
});

function main({ n, type }) {
// For testing, if supplied with an empty type, default to string.
type = type || 'string';

const [first, second] = inputs[type];

bench.start();
Expand Down
3 changes: 3 additions & 0 deletions benchmark/util/inspect-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ function main({ n, len, type }) {
var arr = Array(len);
var i, opts;

// For testing, if supplied with an empty type, default to denseArray.
type = type || 'denseArray';

switch (type) {
case 'denseArray_showHidden':
opts = { showHidden: true };
Expand Down
7 changes: 5 additions & 2 deletions benchmark/util/type-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ const bench = common.createBenchmark(main, {
type: Object.keys(args),
version: ['native', 'js'],
argument: ['true', 'false-primitive', 'false-object'],
millions: ['5']
n: [5e6]
}, {
flags: ['--expose-internals']
});

function main(conf) {
// For testing, if supplied with an empty type, default to ArrayBufferView.
conf.type = conf.type || 'ArrayBufferView';

const util = process.binding('util');
const types = require('internal/util/types');

const n = (+conf.millions * 1e6) | 0;
const n = (+conf.n) | 0;
const func = { native: util, js: types }[conf.version][`is${conf.type}`];
const arg = args[conf.type][conf.argument];

Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-benchmark-util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

require('../common');

const runBenchmark = require('../common/benchmark');

runBenchmark('util',
['argument=false',
'input=',
'method=Array',
'n=1',
'option=none',
'type=',
'version=native']);

0 comments on commit 50fe1a8

Please sign in to comment.