Browse Source

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: https://github.com/nodejs/node/pull/5177
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
v4.x
Andreas Madsen 9 years ago
committed by Myles Borins
parent
commit
c189eec14e
  1. 25
      benchmark/assert/deepequal-prims-and-objs-big-array.js
  2. 25
      benchmark/assert/deepequal-prims-and-objs-big-loop.js
  3. 2
      benchmark/buffers/buffer-read.js
  4. 4
      benchmark/buffers/buffer-tostring.js
  5. 2
      benchmark/buffers/buffer-write.js
  6. 4
      benchmark/common.js

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

@ -1,22 +1,25 @@
'use strict'; 'use strict';
var common = require('../common.js'); var common = require('../common.js');
var assert = require('assert'); var assert = require('assert');
const primValues = {
'null': null,
'undefined': undefined,
'string': 'a',
'number': 1,
'boolean': true,
'object': { 0: 'a' },
'array': [1, 2, 3],
'new-array': new Array([1, 2, 3])
};
var bench = common.createBenchmark(main, { var bench = common.createBenchmark(main, {
prim: [ prim: Object.keys(primValues),
null,
undefined,
'a',
1,
true,
{0: 'a'},
[1, 2, 3],
new Array([1, 2, 3])
],
n: [25] n: [25]
}); });
function main(conf) { function main(conf) {
var prim = conf.prim; var prim = primValues[conf.prim];
var n = +conf.n; var n = +conf.n;
var primArray; var primArray;
var primArrayCompare; var primArrayCompare;

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

@ -1,22 +1,25 @@
'use strict'; 'use strict';
var common = require('../common.js'); var common = require('../common.js');
var assert = require('assert'); var assert = require('assert');
const primValues = {
'null': null,
'undefined': undefined,
'string': 'a',
'number': 1,
'boolean': true,
'object': { 0: 'a' },
'array': [1, 2, 3],
'new-array': new Array([1, 2, 3])
};
var bench = common.createBenchmark(main, { var bench = common.createBenchmark(main, {
prim: [ prim: Object.keys(primValues),
null,
undefined,
'a',
1,
true,
{0: 'a'},
[1, 2, 3],
new Array([1, 2, 3])
],
n: [1e5] n: [1e5]
}); });
function main(conf) { function main(conf) {
var prim = conf.prim; var prim = primValues[conf.prim];
var n = +conf.n; var n = +conf.n;
var x; var x;

2
benchmark/buffers/buffer-read.js

@ -2,7 +2,7 @@
var common = require('../common.js'); var common = require('../common.js');
var bench = common.createBenchmark(main, { var bench = common.createBenchmark(main, {
noAssert: [false, true], noAssert: ['false', 'true'],
buffer: ['fast', 'slow'], buffer: ['fast', 'slow'],
type: ['UInt8', 'UInt16LE', 'UInt16BE', type: ['UInt8', 'UInt16LE', 'UInt16BE',
'UInt32LE', 'UInt32BE', 'UInt32LE', 'UInt32BE',

4
benchmark/buffers/buffer-tostring.js

@ -3,13 +3,13 @@
const common = require('../common.js'); const common = require('../common.js');
const bench = common.createBenchmark(main, { const bench = common.createBenchmark(main, {
arg: [true, false], arg: ['true', 'false'],
len: [0, 1, 64, 1024], len: [0, 1, 64, 1024],
n: [1e7] n: [1e7]
}); });
function main(conf) { function main(conf) {
const arg = conf.arg; const arg = conf.arg === 'true';
const len = conf.len | 0; const len = conf.len | 0;
const n = conf.n | 0; const n = conf.n | 0;
const buf = Buffer(len).fill(42); const buf = Buffer(len).fill(42);

2
benchmark/buffers/buffer-write.js

@ -1,7 +1,7 @@
'use strict'; 'use strict';
var common = require('../common.js'); var common = require('../common.js');
var bench = common.createBenchmark(main, { var bench = common.createBenchmark(main, {
noAssert: [false, true], noAssert: ['false', 'true'],
buffer: ['fast', 'slow'], buffer: ['fast', 'slow'],
type: ['UInt8', 'UInt16LE', 'UInt16BE', type: ['UInt8', 'UInt16LE', 'UInt16BE',
'UInt32LE', 'UInt32BE', 'UInt32LE', 'UInt32BE',

4
benchmark/common.js

@ -152,6 +152,10 @@ Benchmark.prototype._run = function() {
var j = 0; var j = 0;
set.forEach(function(s) { set.forEach(function(s) {
vals.forEach(function(val) { vals.forEach(function(val) {
if (typeof val !== 'number' && typeof val !== 'string') {
throw new TypeError(`configuration "${key}" had type ${typeof val}`);
}
newSet[j++] = s.concat(key + '=' + val); newSet[j++] = s.concat(key + '=' + val);
}); });
}); });

Loading…
Cancel
Save