2017-02-01 07:28:59 +08:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
|
|
const assert = require('assert');
|
2017-06-29 02:34:19 +08:00
|
|
|
|
2017-02-01 07:28:59 +08:00
|
|
|
const bench = common.createBenchmark(main, {
|
2018-08-03 21:30:22 +08:00
|
|
|
n: [2e4],
|
|
|
|
len: [1e2, 1e3],
|
|
|
|
strict: [0, 1],
|
2019-02-01 13:05:17 +08:00
|
|
|
method: [ 'deepEqual', 'notDeepEqual' ],
|
2017-02-01 07:28:59 +08:00
|
|
|
});
|
|
|
|
|
2018-08-03 21:30:22 +08:00
|
|
|
function main({ len, n, method, strict }) {
|
2018-05-30 11:32:42 +08:00
|
|
|
if (!method)
|
|
|
|
method = 'deepEqual';
|
2017-06-29 02:34:19 +08:00
|
|
|
const data = Buffer.allocUnsafe(len + 1);
|
2017-02-01 07:28:59 +08:00
|
|
|
const actual = Buffer.alloc(len);
|
|
|
|
const expected = Buffer.alloc(len);
|
2017-06-29 02:34:19 +08:00
|
|
|
const expectedWrong = Buffer.alloc(len + 1);
|
2017-02-01 07:28:59 +08:00
|
|
|
data.copy(actual);
|
|
|
|
data.copy(expected);
|
2017-06-29 02:34:19 +08:00
|
|
|
data.copy(expectedWrong);
|
2017-02-01 07:28:59 +08:00
|
|
|
|
2018-08-03 21:30:22 +08:00
|
|
|
if (strict) {
|
|
|
|
method = method.replace('eep', 'eepStrict');
|
|
|
|
}
|
2018-05-30 11:32:42 +08:00
|
|
|
const fn = assert[method];
|
2018-01-23 20:17:21 +08:00
|
|
|
const value2 = method.includes('not') ? expectedWrong : expected;
|
|
|
|
|
|
|
|
bench.start();
|
|
|
|
for (var i = 0; i < n; ++i) {
|
|
|
|
fn(actual, value2);
|
2017-02-01 07:28:59 +08:00
|
|
|
}
|
2018-01-23 20:17:21 +08:00
|
|
|
bench.end(n);
|
2017-02-01 07:28:59 +08:00
|
|
|
}
|