summaryrefslogtreecommitdiff
path: root/website/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'website/app.js')
-rw-r--r--website/app.js55
1 files changed, 36 insertions, 19 deletions
diff --git a/website/app.js b/website/app.js
index 66151b6ca..612cc7af0 100644
--- a/website/app.js
+++ b/website/app.js
@@ -1,18 +1,46 @@
-const benchmarkNames = ["hello", "relative_import"];
+// Copyright 2018 the Deno authors. All rights reserved. MIT license.
-(async () => {
- const data = await (await fetch("./data.json")).json();
+export async function getJson(path) {
+ return (await fetch(path)).json();
+}
- const execTimeColumns = benchmarkNames.map(name => [
+const benchmarkNames = ["hello", "relative_import"];
+export function createExecTimeColumns(data) {
+ return benchmarkNames.map(name => [
name,
...data.map(d => {
const benchmark = d.benchmark[name];
- return benchmark ? benchmark.mean : 0;
+ const meanValue = benchmark ? benchmark.mean : 0;
+ return meanValue || 0;
})
]);
+}
+
+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];
+}
- const binarySizeList = data.map(d => d.binary_size || 0);
- const sha1List = data.map(d => d.sha1);
+export async function main() {
+ const data = await getJson("./data.json");
+
+ const execTimeColumns = createExecTimeColumns(data);
+ const binarySizeColumns = createBinarySizeColumns(data);
+ const sha1List = createSha1List(data);
c3.generate({
bindto: "#exec-time-chart",
@@ -27,7 +55,7 @@ const benchmarkNames = ["hello", "relative_import"];
c3.generate({
bindto: "#binary-size-chart",
- data: { columns: [["binary_size", ...binarySizeList]] },
+ data: { columns: binarySizeColumns },
axis: {
x: {
type: "category",
@@ -40,15 +68,4 @@ const benchmarkNames = ["hello", "relative_import"];
}
}
});
-})();
-
-// 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];
}