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
120
121
122
123
124
125
126
127
128
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
export async function getJson(path) {
return (await fetch(path)).json();
}
const benchmarkNames = [
"hello",
"relative_import",
"cold_hello",
"cold_relative_import"
];
export function createExecTimeColumns(data) {
return benchmarkNames.map(name => [
name,
...data.map(d => {
const benchmark = d.benchmark[name];
const meanValue = benchmark ? benchmark.mean : 0;
return meanValue || 0;
})
]);
}
export function createBinarySizeColumns(data) {
return [["binary_size", ...data.map(d => d.binary_size || 0)]];
}
const threadCountNames = ["set_timeout", "fetch_deps"];
export function createThreadCountColumns(data) {
return threadCountNames.map(name => [
name,
...data.map(d => {
const threadCountData = d["thread_count"];
if (!threadCountData) {
return 0;
}
return threadCountData[name] || 0;
})
]);
}
const syscallCountNames = ["hello"];
export function createSyscallCountColumns(data) {
return syscallCountNames.map(name => [
name,
...data.map(d => {
const syscallCountData = d["syscall_count"];
if (!syscallCountData) {
return 0;
}
return syscallCountData[name] || 0;
})
]);
}
export function createSha1List(data) {
return data.map(d => d.sha1);
}
// Formats the byte sizes e.g. 19000 -> 18.55 KB
// Copied from https://stackoverflow.com/a/18650828
export function formatBytes(a, b) {
if (0 == a) return "0 Bytes";
var c = 1024,
d = b || 2,
e = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
f = Math.floor(Math.log(a) / Math.log(c));
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f];
}
export async function main() {
const data = await getJson("./data.json");
const execTimeColumns = createExecTimeColumns(data);
const binarySizeColumns = createBinarySizeColumns(data);
const threadCountColumns = createThreadCountColumns(data);
const syscallCountColumns = createSyscallCountColumns(data);
const sha1List = createSha1List(data);
c3.generate({
bindto: "#exec-time-chart",
data: { columns: execTimeColumns },
axis: {
x: {
type: "category",
categories: sha1List
}
}
});
c3.generate({
bindto: "#binary-size-chart",
data: { columns: binarySizeColumns },
axis: {
x: {
type: "category",
categories: sha1List
},
y: {
tick: {
format: d => formatBytes(d)
}
}
}
});
c3.generate({
bindto: "#thread-count-chart",
data: { columns: threadCountColumns },
axis: {
x: {
type: "category",
categories: sha1List
}
}
});
c3.generate({
bindto: "#syscall-count-chart",
data: { columns: syscallCountColumns },
axis: {
x: {
type: "category",
categories: sha1List
}
}
});
}
|