0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
denoland-deno/website/app.js
2018-09-23 11:54:07 -04:00

54 lines
1.3 KiB
JavaScript

const benchmarkNames = ["hello", "relative_import"];
(async () => {
const data = await (await fetch("./data.json")).json();
const execTimeColumns = benchmarkNames.map(name => [
name,
...data.map(d => {
const benchmark = d.benchmark[name];
return benchmark ? benchmark.mean : 0;
})
]);
const binarySizeList = data.map(d => d.binary_size || 0);
const sha1List = data.map(d => d.sha1);
c3.generate({
bindto: "#exec-time-chart",
data: { columns: execTimeColumns },
axis: {
x: {
type: "category",
categories: sha1List
}
}
});
c3.generate({
bindto: "#binary-size-chart",
data: { columns: [["binary_size", ...binarySizeList]] },
axis: {
x: {
type: "category",
categories: sha1List
},
y: {
tick: {
format: d => formatBytes(d)
}
}
}
});
})();
// Formats the byte sizes e.g. 19000 -> 18.55KB
// Copied from https://stackoverflow.com/a/18650828
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];
}