-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkarma-benchmark-reporter.cjs
48 lines (46 loc) · 1.3 KB
/
karma-benchmark-reporter.cjs
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
const chalk = require('chalk')
const Table = require('tty-table')
exports['reporter:benchmark'] = ['type', BenchmarkReporter]
function BenchmarkReporter (baseReporterDecorator) {
baseReporterDecorator(this)
const resultsPerBrowser = new Map()
this.onBrowserInfo = function (browser, info) {
if (!info.benchmark) return
if (!resultsPerBrowser.has(browser.name)) {
resultsPerBrowser.set(browser.name, info.benchmark)
}
}
this.onRunComplete = function () {
if (resultsPerBrowser.size === 0) return
this.writeCommonMsg(chalk.underline.bold('\nBENCHMARK (times in seconds):\n'))
resultsPerBrowser.forEach((results, browserName) => {
this.writeCommonMsg(` ${chalk.bold(browserName)}:\n`)
const rows = results.map(({ cur, ref }, i) => ({
i: String(i),
cur: cur.toFixed(0),
ref: ref.toFixed(0),
diff: `${(cur / ref * 100).toFixed(2)}%`,
}))
const header = [
{
value: 'i',
align: 'right'
},
{
value: 'ref',
align: 'right'
},
{
value: 'cur',
align: 'right'
},
{
value: 'diff',
align: 'right'
},
]
console.log(Table(header, rows).render())
})
resultsPerBrowser.clear()
}
}