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';
|
2017-02-01 07:28:59 +08:00
|
|
|
var i;
|
2015-12-17 21:05:45 +08:00
|
|
|
|
2017-02-01 07:28:59 +08:00
|
|
|
// Creates new array to avoid loop invariant code motion
|
2017-12-30 10:54:30 +08:00
|
|
|
switch (method) {
|
2017-09-04 05:06:09 +08:00
|
|
|
case '':
|
|
|
|
// Empty string falls through to next line as default, mostly for tests.
|
2017-06-29 02:34:19 +08:00
|
|
|
case 'deepEqual':
|
2017-02-01 07:28:59 +08:00
|
|
|
bench.start();
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
// eslint-disable-next-line no-restricted-properties
|
|
|
|
assert.deepEqual([actual], [expected]);
|
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
break;
|
2017-06-29 02:34:19 +08:00
|
|
|
case 'deepStrictEqual':
|
2017-02-01 07:28:59 +08:00
|
|
|
bench.start();
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
assert.deepStrictEqual([actual], [expected]);
|
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
break;
|
2017-06-29 02:34:19 +08:00
|
|
|
case 'notDeepEqual':
|
|
|
|
bench.start();
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
// eslint-disable-next-line no-restricted-properties
|
|
|
|
assert.notDeepEqual([actual], [expectedWrong]);
|
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
break;
|
|
|
|
case 'notDeepStrictEqual':
|
|
|
|
bench.start();
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
assert.notDeepStrictEqual([actual], [expectedWrong]);
|
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
break;
|
2017-02-01 07:28:59 +08:00
|
|
|
default:
|
|
|
|
throw new Error('Unsupported method');
|
2015-12-17 21:05:45 +08:00
|
|
|
}
|
|
|
|
}
|