-
Notifications
You must be signed in to change notification settings - Fork 40
Description
I was curious how well chai would handle big sets and maps and checked a couple of things and also stumbled across this PR and I am sorry to say that these benchmarks are somewhat flawed.
The Node.js assert module was never used for comparison because the benchmark required a in-existing function that would be replaced with deep-eql in that case. The result is that the node and deep-eql results are actually both from the same library so they should be pretty much identical. However, that is not always the case and they partially differ by a big margin e.g.
buffer x 1,166,637 ops/sec ±6.09% (73 runs sampled)
buffer (node) x 611,182 ops/sec ±2.47% (65 runs sampled)
object literal x 160,121 ops/sec ±2.89% (81 runs sampled)
object literal (node) x 392,734 ops/sec ±2.38% (85 runs sampled)
My main concern with these benchmarks is though, that only very simply objects are used. Having nice numbers for those is awesome but they are normally not an issue. If a complex object is used though, this can be really bad.
// Set with 10000 numbers
const actual = new Set(Array(1e4).fill(1).map((_, i) => len - i - 1))
const expected = new Set(Array(1e4).fill(1).map((_, i) => i))This time compared to Node.js 8.4 (this time for real)
set x 3.89 ops/sec ±1.26% (58 runs sampled)
set (node) x 1,387 ops/sec ±0.33% (138 runs sampled)
So Node.js is more then 350 times as fast in this case.
While checking Sets and Maps further I also noticed the following:
When using Sets twice the work is done that is needed in general because the key and the value are both the value when returned in a forEach.
Worse though: comparing Sets or Maps with Objects does not even work properly!
const deepEql = require('./')
const a = new Set([{}, {a:5}])
const b = new Set([{a:5}, {}])
deepEql(a,b) // falseSorting an array with objects is not possible and that is why this bug exists.
I suggest to have a look at a PR from me that would improve the situation and fix the bug as well nodejs/node#14258.
As chai currently does not have a loose equal comparison the algorithm should be pretty straight forward (otherwise there is quite some extra handling for that).