forked from taichi-dev/taichi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
61 lines (47 loc) · 1.61 KB
/
run.py
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
import os
import warnings
from suite_microbenchmarks import MicroBenchmark
from taichi._lib import core as ti_python_core
from utils import datatime_with_format, dump2json
benchmark_suites = [MicroBenchmark]
class BenchmarkInfo:
def __init__(self):
"""init with commit info"""
self.commit_hash = ti_python_core.get_commit_hash()
self.datetime = datatime_with_format()
self.suites = {}
print(f"commit_hash = {self.commit_hash}")
class BenchmarkSuites:
def __init__(self):
self._suites = []
for suite in benchmark_suites:
self._suites.append(suite())
def run(self):
for suite in self._suites:
suite.run()
def save(self, benchmark_dir="./"):
for suite in self._suites:
suite_dir = os.path.join(benchmark_dir, suite.suite_name)
os.makedirs(suite_dir, exist_ok=True)
suite.save_as_json(suite_dir)
def get_suites_info(self):
info_dict = {}
for suite in self._suites:
info_dict[suite.suite_name] = suite.get_benchmark_info()
return info_dict
def main():
benchmark_dir = os.path.join(os.getcwd(), "results")
os.makedirs(benchmark_dir, exist_ok=True)
# init & run
info = BenchmarkInfo()
suites = BenchmarkSuites()
suites.run()
# save benchmark results & info
suites.save(benchmark_dir)
info.suites = suites.get_suites_info()
info_path = os.path.join(benchmark_dir, "_info.json")
info_str = dump2json(info)
with open(info_path, "w") as f:
print(info_str, file=f)
if __name__ == "__main__":
main()