diff options
-rw-r--r-- | .gitignore | 6 | ||||
-rwxr-xr-x | tools/benchmark.py | 85 | ||||
-rwxr-xr-x | tools/format.py | 2 | ||||
-rw-r--r-- | website/app.js | 26 | ||||
-rw-r--r-- | website/index.html | 14 |
5 files changed, 131 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore index 51eb81ca8..bd850eb16 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,11 @@ Cargo.lock yarn.lock # npm deps node_modules +# editor files .idea - # RLS generated files /target/ +# export dir for gh-pages +/gh-pages +# temp benchmark data +/website/data.json diff --git a/tools/benchmark.py b/tools/benchmark.py new file mode 100755 index 000000000..f0f9e4ac6 --- /dev/null +++ b/tools/benchmark.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python +# Performs benchmark and append data to //website/data.json. +# If //website/data.json doesn't exist, this script tries to import it from gh-pages branch. +# To view the results locally run ./tools/http_server.py and visit +# http://localhost:4545/website + +import os +import sys +import json +import time +import shutil +from util import run, run_output, root_path, build_path + +# The list of the tuples of the benchmark name and arguments +benchmarks = [("hello", ["tests/002_hello.ts", "--reload"]), + ("relative_import", ["tests/003_relative_import.ts", + "--reload"])] + +gh_pages_data_file = "gh-pages/data.json" +data_file = "website/data.json" + + +def read_json(filename): + with open(filename) as json_file: + return json.load(json_file) + + +def write_json(filename, data): + with open(filename, 'w') as outfile: + json.dump(data, outfile) + + +def import_data_from_gh_pages(): + if os.path.exists(data_file): + return + try: + run([ + "git", "clone", "--depth", "1", "-b", "gh-pages", + "https://github.com/denoland/deno.git", "gh-pages" + ]) + shutil.copy(gh_pages_data_file, data_file) + except: + write_json(data_file, []) # writes empty json data + + +def main(argv): + if len(argv) == 2: + build_dir = sys.argv[1] + elif len(argv) == 1: + build_dir = build_path() + else: + print "Usage: tools/benchmark.py [build_dir]" + sys.exit(1) + + deno_path = os.path.join(build_dir, "deno") + benchmark_file = os.path.join(build_dir, "benchmark.json") + + os.chdir(root_path) + import_data_from_gh_pages() + # TODO: Use hyperfine in //third_party + run(["hyperfine", "--export-json", benchmark_file, "--warmup", "3"] + + [deno_path + " " + " ".join(args) for [_, args] in benchmarks]) + all_data = read_json(data_file) + benchmark_data = read_json(benchmark_file) + sha1 = run_output(["git", "rev-parse", "HEAD"]).strip() + new_data = { + "created_at": time.strftime("%Y-%m-%dT%H:%M:%SZ"), + "sha1": sha1, + "benchmark": {} + } + for [[name, _], data] in zip(benchmarks, benchmark_data["results"]): + new_data["benchmark"][name] = { + "mean": data["mean"], + "stddev": data["stddev"], + "user": data["user"], + "system": data["system"], + "min": data["min"], + "max": data["max"] + } + all_data.append(new_data) + write_json(data_file, all_data) + + +if __name__ == '__main__': + main(sys.argv) diff --git a/tools/format.py b/tools/format.py index 47774c44c..b91e75635 100755 --- a/tools/format.py +++ b/tools/format.py @@ -29,7 +29,7 @@ for fn in ["BUILD.gn", ".gn"] + find_exts("build_extra", ".gn", ".gni"): run(["yapf", "-i"] + glob("tools/*.py") + find_exts("build_extra", ".py")) run(["node", prettier, "--write"] + find_exts("js/", ".js", ".ts") + - find_exts("tests/", ".js", ".ts") + + find_exts("tests/", ".js", ".ts") + find_exts("website/", ".js", ".ts") + ["rollup.config.js", "tsconfig.json", "tslint.json"]) # Requires rustfmt 0.8.2 (flags were different in previous versions) diff --git a/website/app.js b/website/app.js new file mode 100644 index 000000000..7a6566a61 --- /dev/null +++ b/website/app.js @@ -0,0 +1,26 @@ +const benchmarkNames = ["hello", "relative_import"]; + +(async () => { + const data = await (await fetch("./data.json")).json(); + + const benchmarkColumns = benchmarkNames.map(name => [ + name, + ...data.map(d => { + const benchmark = d.benchmark[name]; + return benchmark ? benchmark.mean : 0; + }) + ]); + + const sha1List = data.map(d => d.sha1); + + c3.generate({ + bindto: "#benchmark-chart", + data: { columns: benchmarkColumns }, + axis: { + x: { + type: "category", + categories: sha1List + } + } + }); +})(); diff --git a/website/index.html b/website/index.html new file mode 100644 index 000000000..b15a9c949 --- /dev/null +++ b/website/index.html @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html> +<head> + <title>deno benchmark</title> + <link rel="stylesheet" href="https://unpkg.com/c3@0.6.7/c3.min.css"> +</head> +<body> + <div id="benchmark-chart"></div> + <script src="https://unpkg.com/d3@5.7.0/dist/d3.min.js"></script> + <script src="https://unpkg.com/c3@0.6.7/c3.min.js"></script> + <script src="./app.js"></script> +</body> +</html> + |