2015-12-17 21:05:45 +08:00
|
|
|
'use strict';
|
2017-02-01 07:28:59 +08:00
|
|
|
const common = require('../common.js');
|
|
|
|
const assert = require('assert');
|
2016-02-09 04:50:10 +08:00
|
|
|
|
|
|
|
const primValues = {
|
|
|
|
'string': 'a',
|
|
|
|
'number': 1,
|
|
|
|
'object': { 0: 'a' },
|
2018-08-03 21:30:22 +08:00
|
|
|
'array': [1, 2, 3]
|
2016-02-09 04:50:10 +08:00
|
|
|
};
|
|
|
|
|
2017-02-01 07:28:59 +08:00
|
|
|
const bench = common.createBenchmark(main, {
|
2017-12-30 10:54:30 +08:00
|
|
|
primitive: Object.keys(primValues),
|
2018-08-03 21:30:22 +08:00
|
|
|
n: [2e4],
|
|
|
|
strict: [0, 1],
|
2017-06-29 02:34:19 +08:00
|
|
|
method: [
|
|
|
|
'deepEqual',
|
|
|
|
'notDeepEqual',
|
|
|
|
]
|
2015-12-17 21:05:45 +08:00
|
|
|
});
|
|
|
|
|
2018-08-03 21:30:22 +08:00
|
|
|
function main({ n, primitive, method, strict }) {
|
2018-05-30 11:47:41 +08:00
|
|
|
if (!method)
|
|
|
|
method = 'deepEqual';
|
2017-12-30 10:54:30 +08:00
|
|
|
const prim = primValues[primitive];
|
2017-02-01 07:28:59 +08:00
|
|
|
const actual = prim;
|
|
|
|
const expected = prim;
|
2017-06-29 02:34:19 +08:00
|
|
|
const expectedWrong = 'b';
|
2015-12-17 21:05:45 +08:00
|
|
|
|
2018-08-03 21:30:22 +08:00
|
|
|
if (strict) {
|
|
|
|
method = method.replace('eep', 'eepStrict');
|
|
|
|
}
|
2018-05-30 11:47:41 +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]);
|
2015-12-17 21:05:45 +08:00
|
|
|
}
|
2018-01-23 20:17:21 +08:00
|
|
|
bench.end(n);
|
2015-12-17 21:05:45 +08:00
|
|
|
}
|