node/benchmark/assert/deepequal-prims-and-objs-big-loop.js
Rich Trott 3418956349 benchmark: use consistent coding style in assert/*
Files in benchmark/assert/* were sometimes using trailing commas for
multi-line objects and sometimes not, mixing the approaches in the same
file sometimes. Standardize these files to always use trailing commas in
multi-line objects.

Additionally, remove some unnecessary line-wrapping (so that there are
fewer multi-line objects).

PR-URL: https://github.com/nodejs/node/pull/25865
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
2019-02-03 01:48:32 -08:00

39 lines
826 B
JavaScript

'use strict';
const common = require('../common.js');
const assert = require('assert');
const primValues = {
'string': 'a',
'number': 1,
'object': { 0: 'a' },
'array': [1, 2, 3],
};
const bench = common.createBenchmark(main, {
primitive: Object.keys(primValues),
n: [2e4],
strict: [0, 1],
method: [ 'deepEqual', 'notDeepEqual' ],
});
function main({ n, primitive, method, strict }) {
if (!method)
method = 'deepEqual';
const prim = primValues[primitive];
const actual = prim;
const expected = prim;
const expectedWrong = 'b';
if (strict) {
method = method.replace('eep', 'eepStrict');
}
const fn = assert[method];
const value2 = method.includes('not') ? expectedWrong : expected;
bench.start();
for (var i = 0; i < n; ++i) {
fn([actual], [value2]);
}
bench.end(n);
}