This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
collector.js
87 lines (71 loc) · 2.77 KB
/
collector.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const fs = require("fs")
var Collector = function () {
var self = this
self.metrics = {}
self.baseNative = 0.0
self.baseWasm = 0.0
self.FormatMs = function (fl) {
return (fl / 1000000.0).toFixed(2)
}
self.FormatPc = function (fl) {
return (fl > 0 ? "+" : "") + (fl * 100).toFixed(2) + "%"
}
self.CollectBaseCriterionWasmNative = async function (baseDir) {
var masterNativeStats = await self.loadStats(
baseDir + "/Native/base/estimates.json",
)
var masterWasmStats = await self.loadStats(
baseDir + "/Wasm/base/estimates.json",
)
self.baseWasm = masterWasmStats.Median.point_estimate
self.baseNative = masterNativeStats.Median.point_estimate
self.metrics["Master: Wasm"] = `${self.FormatMs(
self.baseWasm,
)} ms (+/- ${self.FormatMs(masterWasmStats.Median.standard_error)} ms)`
self.metrics["Master: Native"] = `${self.FormatMs(
self.baseNative,
)} ms (+/- ${self.FormatMs(masterNativeStats.Median.standard_error)} ms)`
}
self.CollectBranchCriterionWasmNative = async function (baseDir) {
var branchNativeStats = await self.loadStats(
baseDir + "/Native/new/estimates.json",
)
var branchWasmStats = await self.loadStats(
baseDir + "/Wasm/new/estimates.json",
)
var branchWasm = branchWasmStats.Median.point_estimate
var branchNative = branchNativeStats.Median.point_estimate
self.metrics["Branch: Wasm"] = `${self.FormatMs(
branchWasm,
)} ms (+/- ${self.FormatMs(branchWasmStats.Median.standard_error)} ms)`
self.metrics["Branch: Native"] = `${self.FormatMs(
branchNative,
)} ms (+/- ${self.FormatMs(branchNativeStats.Median.standard_error)} ms)`
var changeWasm = (branchWasm - self.baseWasm) / self.baseWasm
var changeNative = (branchNative - self.baseNative) / self.baseNative
self.metrics["Change: Wasm"] = self.FormatPc(changeWasm)
self.metrics["Change: Native"] = self.FormatPc(changeNative)
}
self.CollectBaseCustomRunner = async function (stdout) {
self.baseNative = JSON.parse(stdout)[0]["average"]
self.metrics["Master"] = `${self.FormatMs(self.baseNative)} ms`
}
self.CollectBranchCustomRunner = async function (stdout) {
self.branchNative = JSON.parse(stdout)[0]["average"]
var change = (self.branchNative - self.baseNative) / self.baseNative
self.metrics["Branch"] = `${self.FormatMs(self.branchNative)} ms`
self.metrics["Change"] = self.FormatPc(change)
}
self.loadStats = async function (path) {
var buffer = fs.readFileSync(path)
return JSON.parse(buffer)
}
self.Report = async function () {
var report = ""
for (metric in self.metrics) {
report = report + "\n" + `${metric}: ${self.metrics[metric]}`
}
return report
}
}
module.exports.Collector = Collector