Skip to content

Commit 50fe1a8

Browse files
sarahmeyerTrott
authored andcommitted
tools, benchmark: test util benchmark
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]>
1 parent 64aded3 commit 50fe1a8

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

benchmark/util/format.js

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ const bench = common.createBenchmark(main, {
2121
});
2222

2323
function main({ n, type }) {
24+
// For testing, if supplied with an empty type, default to string.
25+
type = type || 'string';
26+
2427
const [first, second] = inputs[type];
2528

2629
bench.start();

benchmark/util/inspect-array.js

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ function main({ n, len, type }) {
1818
var arr = Array(len);
1919
var i, opts;
2020

21+
// For testing, if supplied with an empty type, default to denseArray.
22+
type = type || 'denseArray';
23+
2124
switch (type) {
2225
case 'denseArray_showHidden':
2326
opts = { showHidden: true };

benchmark/util/type-check.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@ const bench = common.createBenchmark(main, {
2929
type: Object.keys(args),
3030
version: ['native', 'js'],
3131
argument: ['true', 'false-primitive', 'false-object'],
32-
millions: ['5']
32+
n: [5e6]
3333
}, {
3434
flags: ['--expose-internals']
3535
});
3636

3737
function main(conf) {
38+
// For testing, if supplied with an empty type, default to ArrayBufferView.
39+
conf.type = conf.type || 'ArrayBufferView';
40+
3841
const util = process.binding('util');
3942
const types = require('internal/util/types');
4043

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

test/parallel/test-benchmark-util.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const runBenchmark = require('../common/benchmark');
6+
7+
runBenchmark('util',
8+
['argument=false',
9+
'input=',
10+
'method=Array',
11+
'n=1',
12+
'option=none',
13+
'type=',
14+
'version=native']);

0 commit comments

Comments
 (0)