Skip to content

Commit c189eec

Browse files
AndreasMadsenMyles Borins
authored and
Myles Borins
committed
benchmark: fix configuation parameters
The benchmark runner spawns new processes for each configuration. The specific configuration is transfered by process.argv. This means that the values have to be parsed. As of right now only numbers and strings are parsed correctly. However other values such as objects where used. This fixes the benchmarks that used non-string/number values and prevents future issues by asserting the type. PR-URL: #5177 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent 58ad451 commit c189eec

6 files changed

+36
-26
lines changed

benchmark/assert/deepequal-prims-and-objs-big-array.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
'use strict';
22
var common = require('../common.js');
33
var assert = require('assert');
4+
5+
const primValues = {
6+
'null': null,
7+
'undefined': undefined,
8+
'string': 'a',
9+
'number': 1,
10+
'boolean': true,
11+
'object': { 0: 'a' },
12+
'array': [1, 2, 3],
13+
'new-array': new Array([1, 2, 3])
14+
};
15+
416
var bench = common.createBenchmark(main, {
5-
prim: [
6-
null,
7-
undefined,
8-
'a',
9-
1,
10-
true,
11-
{0: 'a'},
12-
[1, 2, 3],
13-
new Array([1, 2, 3])
14-
],
17+
prim: Object.keys(primValues),
1518
n: [25]
1619
});
1720

1821
function main(conf) {
19-
var prim = conf.prim;
22+
var prim = primValues[conf.prim];
2023
var n = +conf.n;
2124
var primArray;
2225
var primArrayCompare;

benchmark/assert/deepequal-prims-and-objs-big-loop.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
'use strict';
22
var common = require('../common.js');
33
var assert = require('assert');
4+
5+
const primValues = {
6+
'null': null,
7+
'undefined': undefined,
8+
'string': 'a',
9+
'number': 1,
10+
'boolean': true,
11+
'object': { 0: 'a' },
12+
'array': [1, 2, 3],
13+
'new-array': new Array([1, 2, 3])
14+
};
15+
416
var bench = common.createBenchmark(main, {
5-
prim: [
6-
null,
7-
undefined,
8-
'a',
9-
1,
10-
true,
11-
{0: 'a'},
12-
[1, 2, 3],
13-
new Array([1, 2, 3])
14-
],
17+
prim: Object.keys(primValues),
1518
n: [1e5]
1619
});
1720

1821
function main(conf) {
19-
var prim = conf.prim;
22+
var prim = primValues[conf.prim];
2023
var n = +conf.n;
2124
var x;
2225

benchmark/buffers/buffer-read.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var common = require('../common.js');
33

44
var bench = common.createBenchmark(main, {
5-
noAssert: [false, true],
5+
noAssert: ['false', 'true'],
66
buffer: ['fast', 'slow'],
77
type: ['UInt8', 'UInt16LE', 'UInt16BE',
88
'UInt32LE', 'UInt32BE',

benchmark/buffers/buffer-tostring.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
const common = require('../common.js');
44

55
const bench = common.createBenchmark(main, {
6-
arg: [true, false],
6+
arg: ['true', 'false'],
77
len: [0, 1, 64, 1024],
88
n: [1e7]
99
});
1010

1111
function main(conf) {
12-
const arg = conf.arg;
12+
const arg = conf.arg === 'true';
1313
const len = conf.len | 0;
1414
const n = conf.n | 0;
1515
const buf = Buffer(len).fill(42);

benchmark/buffers/buffer-write.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
var common = require('../common.js');
33
var bench = common.createBenchmark(main, {
4-
noAssert: [false, true],
4+
noAssert: ['false', 'true'],
55
buffer: ['fast', 'slow'],
66
type: ['UInt8', 'UInt16LE', 'UInt16BE',
77
'UInt32LE', 'UInt32BE',

benchmark/common.js

+4
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ Benchmark.prototype._run = function() {
152152
var j = 0;
153153
set.forEach(function(s) {
154154
vals.forEach(function(val) {
155+
if (typeof val !== 'number' && typeof val !== 'string') {
156+
throw new TypeError(`configuration "${key}" had type ${typeof val}`);
157+
}
158+
155159
newSet[j++] = s.concat(key + '=' + val);
156160
});
157161
});

0 commit comments

Comments
 (0)