index.js
1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
const assertDeepStrictEqual = require('assert').deepStrictEqual;
const tests = require('../spec/tests');
const Benchmark = require('benchmark');
const suite = new Benchmark.Suite;
const equalPackages = {
'fast-deep-equal': require('../index'),
'nano-equal': true,
'shallow-equal-fuzzy': true,
'underscore.isEqual': require('underscore').isEqual,
'lodash.isEqual': require('lodash').isEqual,
'deep-equal': true,
'deep-eql': true,
'assert.deepStrictEqual': (a, b) => {
try { assertDeepStrictEqual(a, b); return true; }
catch(e) { return false; }
}
};
for (const equalName in equalPackages) {
let equalFunc = equalPackages[equalName];
if (equalFunc === true) equalFunc = require(equalName);
for (const testSuite of tests) {
for (const test of testSuite.tests) {
try {
if (equalFunc(test.value1, test.value2) !== test.equal)
console.error('different result', equalName, testSuite.description, test.description);
} catch(e) {
console.error(equalName, testSuite.description, test.description, e);
}
}
}
suite.add(equalName, function() {
for (const testSuite of tests) {
for (const test of testSuite.tests) {
if (test.description != 'pseudo array and equivalent array are not equal')
equalFunc(test.value1, test.value2);
}
}
});
}
console.log();
suite
.on('cycle', (event) => console.log(String(event.target)))
.on('complete', function () {
console.log('The fastest is ' + this.filter('fastest').map('name'));
})
.run({async: true});