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, {
|
2017-06-29 02:34:19 +08:00
|
|
|
n: [1e5],
|
|
|
|
len: [1e2, 1e4],
|
|
|
|
method: [
|
|
|
|
'deepEqual',
|
|
|
|
'deepStrictEqual',
|
|
|
|
'notDeepEqual',
|
|
|
|
'notDeepStrictEqual'
|
|
|
|
]
|
2017-02-01 07:28:59 +08:00
|
|
|
});
|
|
|
|
|
2017-12-30 10:54:30 +08:00
|
|
|
function main({ len, n, method }) {
|
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-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
|
|
|
}
|