-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: Add filter to benchmark, add option to compare with `fast-deep-…
…equal` Follows #1704. == Exclude == Exclude Map/Set tests from the comparison because, unlike QUnit, fast-deep-equal does not perform a deep equal but a shallow strict equal when it comes to Map and Set. ```js const QUnit = require('qunit'); const fde = require('fast-deep-equal/es6'); a = new Set([ { x: 1 }, { y: 2 } ]); b = new Set([ { x: 1 }, { y: 2 } ]); QUnit.equiv(a, b); // true fde(a, b); // false ``` == Local alias == Assign local `equiv` in the bench.js file. Without this, even when a dummy implementation like `QUnit.equiv = (a, b) { return a === b; }` was still reported as 3X slower than fast-deep-equal holding the identical function. ``` require('fast-deep-equal/es6').toString().slice(0, 100); //> 'function equal(a, b) { if (a === b) return true; // …' require('qunit').equiv+''; //> 'function equiv(a, b) { if (a === b) return true; // …' ``` For example (with the above fake implementation): ``` fast-deep-equal (primitives) x 648,076 ops/sec ±0.27% (89 runs sampled) QUnit.innerEquiv (primitives) x 255,011 ops/sec ±0.22% (90 runs sampled) ``` I eventually figured out this is because without the alias, our benchmark case has to resolve "QUnit" of `QUnit.equiv` through every lexical scope up to the global sope, and then access the (theoretically mutable) "equiv" property, and so this every time. For very sensitive workloads (like the "QUnit.equiv primitives" fixture), which basically just hit the first `a === b` condition and return early, this is visible in the benchmark results.
- Loading branch information
Showing
6 changed files
with
67 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,34 @@ | ||
/* eslint-env node */ | ||
|
||
global.QUnit = require('qunit'); | ||
|
||
if (process.argv[2] === 'fast-deep-equal') { | ||
const fde = require('fast-deep-equal/es6'); | ||
const accept = process.argv[3] | ||
? (name) => name.includes(process.argv[3]) | ||
: (name) => !/map|set/i.test(name); | ||
global.QUnitBenchInject = function (hook, group, suite) { | ||
if (hook === 'accept') { | ||
return accept(group.name); | ||
} | ||
if (hook === 'test') { | ||
group.pairs.forEach((pair, i) => { | ||
const res = fde(pair.a, pair.b); | ||
if (res !== pair.equal) { | ||
console.log(pair); | ||
throw new Error(`Unexpected fast-deep-equal return in "${group.name}" at pairs[${i}]\n Expected: ${pair.equal}\n Actual: ${res}`); | ||
} | ||
}); | ||
} | ||
if (hook === 'add') { | ||
suite.add(`fast-deep-equal (${group.name})`, function () { | ||
for (const pair of group.pairs) { | ||
fde(pair.a, pair.b); | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
|
||
require('./fixture-equiv.js'); | ||
require('./bench.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"private": true, | ||
"devDependencies": { | ||
"fast-deep-equal": "3.1.3", | ||
"qunit": "file:../.." | ||
} | ||
} |