mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 15:30:56 +01:00
3c4c0db26a
The benchmarks for `assert` all take a `method` configuration option, but the allowable values are different across the files. For each benchmark, provide an arbitrary default if `method` is set to an empty string. This allows all the `assert` benchmarks to be run with a single command but only on a single method. This is primarily useful for testing that the assert benchmark files don't contain egregious errors. (In other words, it's useful for testing.) PR-URL: https://github.com/nodejs/node/pull/15174 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
76 lines
1.7 KiB
JavaScript
76 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
const assert = require('assert');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [1e6],
|
|
size: [1e2, 1e3, 1e4],
|
|
method: [
|
|
'deepEqual',
|
|
'deepStrictEqual',
|
|
'notDeepEqual',
|
|
'notDeepStrictEqual'
|
|
]
|
|
});
|
|
|
|
function createObj(source, add = '') {
|
|
return source.map((n) => ({
|
|
foo: 'yarp',
|
|
nope: {
|
|
bar: `123${add}`,
|
|
a: [1, 2, 3],
|
|
baz: n
|
|
}
|
|
}));
|
|
}
|
|
|
|
function main(conf) {
|
|
const size = +conf.size;
|
|
// TODO: Fix this "hack"
|
|
const n = (+conf.n) / size;
|
|
var i;
|
|
|
|
const source = Array.apply(null, Array(size));
|
|
const actual = createObj(source);
|
|
const expected = createObj(source);
|
|
const expectedWrong = createObj(source, '4');
|
|
|
|
switch (conf.method) {
|
|
case '':
|
|
// Empty string falls through to next line as default, mostly for tests.
|
|
case 'deepEqual':
|
|
bench.start();
|
|
for (i = 0; i < n; ++i) {
|
|
// eslint-disable-next-line no-restricted-properties
|
|
assert.deepEqual(actual, expected);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'deepStrictEqual':
|
|
bench.start();
|
|
for (i = 0; i < n; ++i) {
|
|
assert.deepStrictEqual(actual, expected);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'notDeepEqual':
|
|
bench.start();
|
|
for (i = 0; i < n; ++i) {
|
|
// eslint-disable-next-line no-restricted-properties
|
|
assert.notDeepEqual(actual, expectedWrong);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'notDeepStrictEqual':
|
|
bench.start();
|
|
for (i = 0; i < n; ++i) {
|
|
assert.notDeepStrictEqual(actual, expectedWrong);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
default:
|
|
throw new Error('Unsupported method');
|
|
}
|
|
}
|