-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark.js
33 lines (28 loc) · 1.01 KB
/
benchmark.js
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
require('colors');
var Benchmark = require('benchmark')
var testLibs = {
'jsondiffpatch': require('./tests/jsondiffpatch'),
'deep-diff': require('./tests/deep-diff'),
'json-diff': require('./tests/json-diff'),
'odiff': require('./tests/odiff'),
}
var tests = Object.keys(testLibs)
function testDiffCreation(title, testMethodName, next) {
var suite = new Benchmark.Suite()
tests.forEach(function _checkResults(name) {
suite.add(name.magenta + ' ' + title + ': '.green, testLibs[name][testMethodName])
})
return suite
.on('cycle', function(event) {
console.log('Benchmarked:'.yellow, String(event.target).green)
})
.on('complete', function() {
console.log('Fastest is '.magenta + String(this.filter('fastest').map('name')).red.bold);
if (next) { next(); }
})
.run({ 'async': false })
}
console.log('=== TESTS OPS/SECOND ==='.magenta);
testDiffCreation('Simple Diffs Benchmark', 'getArrayOfSequentialDiffs', function _next() {
testDiffCreation('Variable String Test', 'getVariableStringDiffs');
});