mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
841279d79c
This reworks most assert benchmarks to provide more reliable test cases that also test more cases than before while keeping the runtime low. Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de> PR-URL: https://github.com/nodejs/node/pull/46593 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
'use strict';
|
|
const common = require('../common.js');
|
|
const assert = require('assert');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [2e4],
|
|
len: [1e2, 1e3],
|
|
strict: [0, 1],
|
|
arrayBuffer: [0, 1],
|
|
method: ['deepEqual', 'notDeepEqual', 'unequal_length'],
|
|
}, {
|
|
combinationFilter: (p) => {
|
|
return p.strict === 1 || p.method === 'deepEqual';
|
|
},
|
|
});
|
|
|
|
function main({ len, n, method, strict, arrayBuffer }) {
|
|
let actual = Buffer.alloc(len);
|
|
let expected = Buffer.alloc(len + Number(method === 'unequal_length'));
|
|
|
|
|
|
if (method === 'unequal_length') {
|
|
method = 'notDeepEqual';
|
|
}
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
actual.writeInt8(i % 128, i);
|
|
expected.writeInt8(i % 128, i);
|
|
}
|
|
|
|
if (method.includes('not')) {
|
|
const position = Math.floor(len / 2);
|
|
expected[position] = expected[position] + 1;
|
|
}
|
|
|
|
if (strict) {
|
|
method = method.replace('eep', 'eepStrict');
|
|
}
|
|
|
|
const fn = assert[method];
|
|
|
|
if (arrayBuffer) {
|
|
actual = actual.buffer;
|
|
expected = expected.buffer;
|
|
}
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; ++i) {
|
|
fn(actual, expected);
|
|
}
|
|
bench.end(n);
|
|
}
|