blob: d435c96553c6e38ac6a0f462795797f7c9096119 (
plain)
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
|
var fs = require('fs')
var benchmarkResultFilename = './tmp/benchmark.json'
function benchmarkJSONReporter () {
var benchmarkResult = {}
this.onSpecComplete = function (_, result) {
var fnName = result.benchmark.suite
var libraryName = result.benchmark.name
var operationsPerSecond = Math.floor(result.benchmark.hz)
if (!benchmarkResult[fnName]) {
benchmarkResult[fnName] = {}
}
benchmarkResult[fnName][libraryName] = operationsPerSecond
}
this.onRunComplete = function () {
var benchmarkResultArray = []
for (var fnName in benchmarkResult) {
if (benchmarkResult.hasOwnProperty(fnName)) {
var element = {fn: fnName}
if (benchmarkResult[fnName]['date-fns']) {
element.dateFns = benchmarkResult[fnName]['date-fns']
}
if (benchmarkResult[fnName]['Moment.js']) {
element.moment = benchmarkResult[fnName]['Moment.js']
}
benchmarkResultArray.push(element)
}
}
fs.writeFile(benchmarkResultFilename, JSON.stringify(benchmarkResultArray), 'utf-8', function (err) {
if (err) {
throw err
}
console.log('See results at ' + benchmarkResultFilename)
})
}
}
module.exports = benchmarkJSONReporter
|