-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathbench.py
More file actions
113 lines (88 loc) · 3.53 KB
/
Copy pathbench.py
File metadata and controls
113 lines (88 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Copyright 2021 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Check the impact of a local change on a benchmark."""
import subprocess
import sys
import repo_util
def main(argv):
if argv.platforms != ["JVM"] and subprocess.call(
"v8 -e '' && sm -e ''", shell=True
):
print("Make sure V8 and SpiderMonkey is installed via jsvu")
sys.exit(1)
if argv.bench_names == ["all"]:
bench_map = _get_bench_map()
bench_names = bench_map.keys()
elif argv.bench_names == ["transpiler"]:
assert argv.platforms == ["JVM"], "Transpiler benchmarks only support JVM"
bench_map = _get_transpiler_bench_map()
bench_names = bench_map.keys()
else:
bench_map = _get_bench_map() | _get_transpiler_bench_map()
bench_names = argv.bench_names
# Benchs as list of (name1, {j2cl: target1, j2wasm: target1}) pairs
benchs = [
(n, repo_util.get_benchmarks(bench_map[n] + "_local", argv))
for n in bench_names
]
print("Building...")
# Join all the targets to build them in one shot.
targets = sum([list(bench.values()) for (_, bench) in benchs], [])
repo_util.build(targets)
multi_platform = len(argv.platforms) > 1 or (
# For web, not specifying a JS VM also results in multiple platforms.
argv.platforms[0] != "JVM" and not argv.js_vm
)
if multi_platform:
print("Starting benchmarks.")
else:
print(f"Starting benchmarks for {argv.platforms[0]}.")
for name, bench_set in benchs:
if multi_platform:
print(f"[{name}]")
else:
print(name, end=": ", flush=True)
for platform, target in bench_set.items():
if multi_platform:
print(platform, end=": ", flush=True)
print(repo_util.run_cmd([repo_util.BIN_DIR + target], shell=True), end="")
_JRE_BENCHMARK_LIST_FILE = "benchmarking/java/com/google/j2cl/benchmarks/jre/benchmark_list.txt"
_OCTANE_BENCHMARK_LIST_FILE = "benchmarking/java/com/google/j2cl/benchmarks/octane/benchmark_list.txt"
_TRANSPILER_BENCHMARK_LIST_FILE = "benchmarking/java/com/google/j2cl/benchmarks/transpiler/benchmark_list.txt"
def _get_bench_map():
repo_util.build([_JRE_BENCHMARK_LIST_FILE, _OCTANE_BENCHMARK_LIST_FILE])
bench_names = {}
for bench_name in _read_gen_file(_JRE_BENCHMARK_LIST_FILE):
bench_names[bench_name] = "jre/" + bench_name
for bench_name in _read_gen_file(_OCTANE_BENCHMARK_LIST_FILE):
bench_names[bench_name] = "octane/" + bench_name
return bench_names
def _get_transpiler_bench_map():
repo_util.build([_TRANSPILER_BENCHMARK_LIST_FILE])
bench_names = {}
for bench_name in _read_gen_file(_TRANSPILER_BENCHMARK_LIST_FILE):
bench_names[bench_name] = "transpiler/" + bench_name
return bench_names
def _read_gen_file(file_path):
with open(repo_util.BIN_DIR + file_path, "rt") as my_file:
return my_file.read().splitlines()
def add_arguments(parser):
parser.add_argument(
"--js_vm",
default="",
choices=["v8", "sm"],
help="JS VM to run the benchmarks on.",
)
parser.add_argument(
"bench_names", nargs="+", metavar="<name>", help="Benchmark names")