2018-09-24 11:31:14 -04:00
|
|
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
2018-09-21 12:06:59 -04:00
|
|
|
|
2018-09-24 11:31:14 -04:00
|
|
|
export async function getJson(path) {
|
|
|
|
return (await fetch(path)).json();
|
|
|
|
}
|
2018-09-21 12:06:59 -04:00
|
|
|
|
2018-09-24 11:31:14 -04:00
|
|
|
const benchmarkNames = ["hello", "relative_import"];
|
|
|
|
export function createExecTimeColumns(data) {
|
|
|
|
return benchmarkNames.map(name => [
|
2018-09-21 12:06:59 -04:00
|
|
|
name,
|
|
|
|
...data.map(d => {
|
|
|
|
const benchmark = d.benchmark[name];
|
2018-09-24 11:31:14 -04:00
|
|
|
const meanValue = benchmark ? benchmark.mean : 0;
|
|
|
|
return meanValue || 0;
|
2018-09-21 12:06:59 -04:00
|
|
|
})
|
|
|
|
]);
|
2018-09-24 11:31:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function createBinarySizeColumns(data) {
|
|
|
|
return [["binary_size", ...data.map(d => d.binary_size || 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];
|
|
|
|
}
|
2018-09-21 12:06:59 -04:00
|
|
|
|
2018-09-24 11:31:14 -04:00
|
|
|
export async function main() {
|
|
|
|
const data = await getJson("./data.json");
|
|
|
|
|
|
|
|
const execTimeColumns = createExecTimeColumns(data);
|
|
|
|
const binarySizeColumns = createBinarySizeColumns(data);
|
|
|
|
const sha1List = createSha1List(data);
|
2018-09-21 12:06:59 -04:00
|
|
|
|
|
|
|
c3.generate({
|
2018-09-23 11:54:07 -04:00
|
|
|
bindto: "#exec-time-chart",
|
|
|
|
data: { columns: execTimeColumns },
|
2018-09-21 12:06:59 -04:00
|
|
|
axis: {
|
|
|
|
x: {
|
|
|
|
type: "category",
|
|
|
|
categories: sha1List
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2018-09-23 11:54:07 -04:00
|
|
|
|
|
|
|
c3.generate({
|
|
|
|
bindto: "#binary-size-chart",
|
2018-09-24 11:31:14 -04:00
|
|
|
data: { columns: binarySizeColumns },
|
2018-09-23 11:54:07 -04:00
|
|
|
axis: {
|
|
|
|
x: {
|
|
|
|
type: "category",
|
|
|
|
categories: sha1List
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
tick: {
|
|
|
|
format: d => formatBytes(d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|