From 9203e983d1536618fb07b3ffd95da177c9bbfdfc Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 24 Sep 2018 00:54:07 +0900 Subject: [PATCH] benchmark: track the binary size (#804) --- tools/benchmark.py | 1 + website/README.md | 23 +++++++++++++++++++++++ website/app.js | 34 +++++++++++++++++++++++++++++++--- website/index.html | 5 ++++- 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 website/README.md diff --git a/tools/benchmark.py b/tools/benchmark.py index f0f9e4ac62..d9decefbb7 100755 --- a/tools/benchmark.py +++ b/tools/benchmark.py @@ -66,6 +66,7 @@ def main(argv): new_data = { "created_at": time.strftime("%Y-%m-%dT%H:%M:%SZ"), "sha1": sha1, + "binary_size": os.path.getsize(deno_path), "benchmark": {} } for [[name, _], data] in zip(benchmarks, benchmark_data["results"]): diff --git a/website/README.md b/website/README.md new file mode 100644 index 0000000000..dece0c7ff0 --- /dev/null +++ b/website/README.md @@ -0,0 +1,23 @@ +## About benchmark data + +The benchmark chart supposes `//website/data.json` has the signature of `BenchmarkData[]` where `BenchmarkData` is defined like the below: + +```typescript +interface ExecTimeData { + mean: number + stddev: number + user: number + system: number + min: number + max: number +} + +interface BenchmarkData { + created_at: string, + sha1: string, + binary_size?: number, + benchmark: { + [key: string]: ExecTimeData + } +} +``` diff --git a/website/app.js b/website/app.js index 7a6566a61b..66151b6cac 100644 --- a/website/app.js +++ b/website/app.js @@ -3,7 +3,7 @@ const benchmarkNames = ["hello", "relative_import"]; (async () => { const data = await (await fetch("./data.json")).json(); - const benchmarkColumns = benchmarkNames.map(name => [ + const execTimeColumns = benchmarkNames.map(name => [ name, ...data.map(d => { const benchmark = d.benchmark[name]; @@ -11,11 +11,12 @@ const benchmarkNames = ["hello", "relative_import"]; }) ]); + const binarySizeList = data.map(d => d.binary_size || 0); const sha1List = data.map(d => d.sha1); c3.generate({ - bindto: "#benchmark-chart", - data: { columns: benchmarkColumns }, + bindto: "#exec-time-chart", + data: { columns: execTimeColumns }, axis: { x: { type: "category", @@ -23,4 +24,31 @@ const benchmarkNames = ["hello", "relative_import"]; } } }); + + 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]; +} diff --git a/website/index.html b/website/index.html index b15a9c9498..7cb8b02989 100644 --- a/website/index.html +++ b/website/index.html @@ -5,7 +5,10 @@ -
+

Execution time chart

+
+

Binary size chart

+