-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperf_parser.js
More file actions
119 lines (115 loc) · 2.81 KB
/
perf_parser.js
File metadata and controls
119 lines (115 loc) · 2.81 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const fs = require("fs");
const categories = [
"abort_controller",
"assert",
"async_hooks",
"blob",
"buffers",
"child_process",
"cluster",
"console",
// 'crypto',
"dgram",
"diagnostics_channel",
"dns",
"domain",
"error",
"es",
"esm",
"events",
"ffi",
"fs",
"http",
"http2",
"https",
"internal",
"mime",
"misc",
"module",
"napi",
"net",
"os",
"path",
"perf_hooks",
"permission",
"process",
"querystring",
"readline",
"source_map",
"sqlite",
"streams",
"string_decoder",
"test_runner",
"timers",
"tls",
"ts",
"url",
"util",
"v8",
"validators",
"vm",
"websocket",
"webstorage",
"webstreams",
"worker",
"zlib",
];
const sortData = (data) =>
data.sort((item1, item2) => {
if (item1.confidence > item2.confidence) {
return -1;
} else if (item1.confidence < item2.confidence) {
return 1;
} else {
if (item1.improvement > item2.improvement) {
return -1;
} else if (item1.improvement < item2.improvement) {
return 1;
} else {
return 0;
}
}
});
const data = [];
const confidences = {};
for (const category of categories) {
try {
const categoryLines = fs
.readFileSync(`.\\data\\${category}.txt`)
.toString()
.split("\r\n")
.slice(1, -8);
const categoryData = categoryLines.map((line) => {
const chunks = line.split(" ").filter(Boolean);
const confidenceString = chunks[chunks.length - 1 - 5];
const confidence =
confidenceString.startsWith("*") && confidenceString.endsWith("*")
? confidenceString.length
: 0;
const improvementString = chunks[chunks.length - 1 - 4];
const improvement = +improvementString;
if (!confidences[confidence]) {
confidences[confidence] = [];
}
confidences[confidence].push(improvement);
return { line, confidence, improvement };
});
data.push(...categoryData);
const categorySortedData = sortData(categoryData);
const categoryText = categorySortedData.reduce(
(txt, dat) => (txt ? `${txt}\r\n${dat.line}` : dat.line),
"",
);
fs.writeFileSync(`.\\results\\${category}_res.txt`, categoryText);
} catch (e) {}
}
for (const [confidence, improvements] of Object.entries(confidences)) {
const validImprovements = improvements.filter((val) => typeof val === "number" && !isNaN(val));
const better = validImprovements.filter((val) => val > 0).length;
const worse = validImprovements.filter((val) => val < 0).length;
const sum = validImprovements.reduce((sum, val) => sum + val, 0);
const avg = sum / validImprovements.length;
console.log(
`Confidence level ${confidence} has ${improvements.length} benchmarks, ${better} better, ${worse} worse, and an average improvement of ${avg.toFixed(2)} %`,
);
}