Skip to content

Commit

Permalink
Merge branch 'streamich-various'
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Nov 30, 2019
2 parents 299fb32 + 16da7a4 commit b2756a7
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 37 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ console.log(equal(Int16Array([1, 2]), Int16Array([1, 2]))); // true
Node.js v12.6.0:

```
fast-deep-equal x 263,304 ops/sec ±0.57% (86 runs sampled)
fast-deep-equal/es6 x 210,257 ops/sec ±0.34% (89 runs sampled)
fast-equals x 233,740 ops/sec ±0.40% (91 runs sampled)
nano-equal x 187,624 ops/sec ±0.30% (93 runs sampled)
shallow-equal-fuzzy x 139,305 ops/sec ±0.37% (91 runs sampled)
underscore.isEqual x 72,636 ops/sec ±0.26% (89 runs sampled)
lodash.isEqual x 37,684 ops/sec ±1.14% (91 runs sampled)
deep-equal x 2,390 ops/sec ±0.36% (88 runs sampled)
deep-eql x 36,353 ops/sec ±0.55% (90 runs sampled)
ramda.equals x 12,169 ops/sec ±0.39% (92 runs sampled)
util.isDeepStrictEqual x 46,720 ops/sec ±0.38% (92 runs sampled)
assert.deepStrictEqual x 461 ops/sec ±0.72% (86 runs sampled)
fast-deep-equal x 261,950 ops/sec ±0.52% (89 runs sampled)
fast-deep-equal/es6 x 212,991 ops/sec ±0.34% (92 runs sampled)
fast-equals x 230,957 ops/sec ±0.83% (85 runs sampled)
nano-equal x 187,995 ops/sec ±0.53% (88 runs sampled)
shallow-equal-fuzzy x 138,302 ops/sec ±0.49% (90 runs sampled)
underscore.isEqual x 74,423 ops/sec ±0.38% (89 runs sampled)
lodash.isEqual x 36,637 ops/sec ±0.72% (90 runs sampled)
deep-equal x 2,310 ops/sec ±0.37% (90 runs sampled)
deep-eql x 35,312 ops/sec ±0.67% (91 runs sampled)
ramda.equals x 12,054 ops/sec ±0.40% (91 runs sampled)
util.isDeepStrictEqual x 46,440 ops/sec ±0.43% (90 runs sampled)
assert.deepStrictEqual x 456 ops/sec ±0.71% (88 runs sampled)
The fastest is fast-deep-equal
```
Expand Down
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"shallow-equal-fuzzy": "latest",
"underscore": "latest"
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Fast deep equal",
"main": "index.js",
"scripts": {
"eslint": "eslint *.js benchmark spec",
"eslint": "eslint *.js benchmark/*.js spec/*.js",
"build": "node build",
"benchmark": "npm i && npm run build && cd ./benchmark && npm i && node ./",
"test-spec": "mocha spec/*.spec.js -R spec",
Expand Down
27 changes: 24 additions & 3 deletions spec/es6tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,18 @@ module.exports = [
value1: undefined,
value2: new Map,
equal: false
}
},
{
description: 'map and a pseudo map are not equal',
value1: map({}),
value2: {
constructor: Map,
size: 0,
has: () => true,
get: () => 1,
},
equal: false
},
]
},

Expand Down Expand Up @@ -228,7 +239,17 @@ module.exports = [
value1: set([undefined]),
value2: set([]),
equal: false
}
},
{
description: 'set and pseudo set are not equal',
value1: new Set,
value2: {
constructor: Set,
size: 0,
has: () => true,
},
equal: false
},
]
},

Expand Down Expand Up @@ -287,7 +308,7 @@ module.exports = [
},
{
description: 'pseudo array and equivalent typed array are not equal',
value1: {'0': 1, '1': 2, length: 2},
value1: {'0': 1, '1': 2, length: 2, constructor: Int32Array},
value2: new Int32Array([1, 2]),
equal: false
}
Expand Down
3 changes: 3 additions & 0 deletions spec/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ function testCases(equalFunc, suiteName, suiteTests) {
(test.skip ? it.skip : it)(test.description, function() {
assert.strictEqual(equalFunc(test.value1, test.value2), test.equal);
});
(test.skip ? it.skip : it)(test.description + ' (reverse arguments)', function() {
assert.strictEqual(equalFunc(test.value2, test.value1), test.equal);
});
});
});
});
Expand Down
26 changes: 6 additions & 20 deletions src/index.jst
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,23 @@ module.exports = function equal(a, b) {
}

{{? it.es6 }}
if (a instanceof Map) {
if ((a instanceof Map) && (b instanceof Map)) {
if (a.size !== b.size) return false;
for(i of a.entries())
for (i of a.entries())
if (!b.has(i[0])) return false;

for(i of a.entries())
for (i of a.entries())
if (!equal(i[1], b.get(i[0]))) return false;

return true;
}

if (a instanceof Set) {
if ((a instanceof Set) && (b instanceof Set)) {
if (a.size !== b.size) return false;
for(i of a.entries())
for (i of a.entries())
if (!b.has(i[0])) return false;

return true;
}

if (a.constructor.BYTES_PER_ELEMENT && (
a instanceof Int8Array ||
a instanceof Uint8Array ||
a instanceof Uint8ClampedArray ||
a instanceof Int16Array ||
a instanceof Uint16Array ||
a instanceof Int32Array ||
a instanceof Uint32Array ||
a instanceof Float32Array ||
a instanceof Float64Array ||
(envHasBigInt64Array && (a instanceof BigInt64Array || a instanceof BigUint64Array))
)) {
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
length = a.length;
if (length != b.length) return false;
for (i = length; i-- !== 0;)
Expand Down

0 comments on commit b2756a7

Please sign in to comment.