node/benchmark/assert/deepequal-prims-and-objs-big-loop.js
Ruben Bridgewater 5442c28b65
benchmark: improve assert benchmarks
This reduces the runtime and makes sure the strict and loose options
can be tested individually.

Besides that a couple of redundant cases were removed.

PR-URL: https://github.com/nodejs/node/pull/22211
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-08-13 11:46:40 +02:00

42 lines
835 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);
}