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 = {
|
|
|
|
'null': null,
|
|
|
|
'undefined': undefined,
|
|
|
|
'string': 'a',
|
|
|
|
'number': 1,
|
|
|
|
'boolean': true,
|
|
|
|
'object': { 0: 'a' },
|
|
|
|
'array': [1, 2, 3],
|
|
|
|
'new-array': new Array([1, 2, 3])
|
|
|
|
};
|
|
|
|
|
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),
|
2017-02-01 07:28:59 +08:00
|
|
|
n: [1e6],
|
2017-06-29 02:34:19 +08:00
|
|
|
method: [
|
|
|
|
'deepEqual',
|
|
|
|
'deepStrictEqual',
|
|
|
|
'notDeepEqual',
|
|
|
|
'notDeepStrictEqual'
|
|
|
|
]
|
2015-12-17 21:05:45 +08:00
|
|
|
});
|
|
|
|
|
2017-12-30 10:54:30 +08:00
|
|
|
function main({ n, primitive, method }) {
|
|
|
|
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-01-23 20:17:21 +08:00
|
|
|
// eslint-disable-next-line no-restricted-properties
|
|
|
|
const fn = method !== '' ? assert[method] : assert.deepEqual;
|
|
|
|
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
|
|
|
}
|