2017-02-01 00:28:59 +01:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
|
|
const assert = require('assert');
|
2017-06-28 20:34:19 +02:00
|
|
|
|
2017-02-01 00:28:59 +01:00
|
|
|
const bench = common.createBenchmark(main, {
|
2018-08-03 15:30:22 +02:00
|
|
|
n: [2e4],
|
|
|
|
len: [1e2, 1e3],
|
|
|
|
strict: [0, 1],
|
2023-02-09 22:07:11 +01:00
|
|
|
arrayBuffer: [0, 1],
|
|
|
|
method: ['deepEqual', 'notDeepEqual', 'unequal_length'],
|
|
|
|
}, {
|
|
|
|
combinationFilter: (p) => {
|
|
|
|
return p.strict === 1 || p.method === 'deepEqual';
|
|
|
|
},
|
2017-02-01 00:28:59 +01:00
|
|
|
});
|
|
|
|
|
2023-02-09 22:07:11 +01:00
|
|
|
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;
|
|
|
|
}
|
2017-02-01 00:28:59 +01:00
|
|
|
|
2018-08-03 15:30:22 +02:00
|
|
|
if (strict) {
|
|
|
|
method = method.replace('eep', 'eepStrict');
|
|
|
|
}
|
2023-02-09 22:07:11 +01:00
|
|
|
|
2018-05-30 05:32:42 +02:00
|
|
|
const fn = assert[method];
|
2023-02-09 22:07:11 +01:00
|
|
|
|
|
|
|
if (arrayBuffer) {
|
|
|
|
actual = actual.buffer;
|
|
|
|
expected = expected.buffer;
|
|
|
|
}
|
2018-01-23 13:17:21 +01:00
|
|
|
|
|
|
|
bench.start();
|
2019-11-12 19:56:03 +01:00
|
|
|
for (let i = 0; i < n; ++i) {
|
2023-02-09 22:07:11 +01:00
|
|
|
fn(actual, expected);
|
2017-02-01 00:28:59 +01:00
|
|
|
}
|
2018-01-23 13:17:21 +01:00
|
|
|
bench.end(n);
|
2017-02-01 00:28:59 +01:00
|
|
|
}
|