wallet-core/node_modules/fast-deep-equal/benchmark/index.js

57 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-08-14 05:01:11 +02:00
'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});