0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 15:30:56 +01:00
nodejs/benchmark/assert/deepequal-prims-and-objs-big-array.js
Andreas Madsen 15720fa25a 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>
2016-02-26 20:29:10 +11:00

41 lines
779 B
JavaScript

'use strict';
var common = require('../common.js');
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, {
prim: Object.keys(primValues),
n: [25]
});
function main(conf) {
var prim = primValues[conf.prim];
var n = +conf.n;
var primArray;
var primArrayCompare;
var x;
primArray = new Array();
primArrayCompare = new Array();
for (x = 0; x < (1e5); x++) {
primArray.push(prim);
primArrayCompare.push(prim);
}
bench.start();
for (x = 0; x < n; x++) {
assert.deepEqual(primArray, primArrayCompare);
}
bench.end(n);
}