-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathperformance.py
141 lines (97 loc) · 3.05 KB
/
performance.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from time import time
from termgraph import termgraph as tg
from maro.backends.frame import FrameBase, FrameNode, NodeAttribute, NodeBase, node
NODE1_NUMBER = 100
NODE2_NUMBER = 100
MAX_TICK = 10000
READ_WRITE_NUMBER = 10000000
STATES_QURING_TIME = 10000
TAKE_SNAPSHOT_TIME = 10000
AVG_TIME = 4
@node("node1")
class TestNode1(NodeBase):
a = NodeAttribute("i")
b = NodeAttribute("i")
c = NodeAttribute("i")
d = NodeAttribute("i")
e = NodeAttribute("i", 16)
@node("node2")
class TestNode2(NodeBase):
b = NodeAttribute("i", 20)
class TestFrame(FrameBase):
node1 = FrameNode(TestNode1, NODE1_NUMBER)
node2 = FrameNode(TestNode2, NODE2_NUMBER)
def __init__(self, backend_name):
super().__init__(
enable_snapshot=True,
total_snapshot=TAKE_SNAPSHOT_TIME,
backend_name=backend_name,
)
def build_frame(backend_name: str):
return TestFrame(backend_name)
def attribute_access(frame, times: int):
"""Return time cost (in seconds) for attribute acceesing test"""
start_time = time()
n1 = frame.node1[0]
for _ in range(times):
n1.a
n1.a = 12
return time() - start_time
def take_snapshot(frame, times: int):
"""Return times cost (in seconds) for take_snapshot operation"""
start_time = time()
for i in range(times):
frame.take_snapshot(i)
return time() - start_time
def snapshot_query(frame, times: int):
"""Return time cost (in seconds) for snapshot querying"""
start_time = time()
for i in range(times):
states = frame.snapshots["node1"][i::"a"]
return time() - start_time
if __name__ == "__main__":
chart_colors = [91, 94]
chart_args = {
"filename": "-",
"title": "Performance comparison between cpp and np backends",
"width": 40,
"format": "{:<5.2f}",
"suffix": "",
"no_labels": False,
"color": None,
"vertical": False,
"stacked": False,
"different_scale": False,
"calendar": False,
"start_dt": None,
"custom_tick": "",
"delim": "",
"verbose": False,
"version": False,
"histogram": False,
"no_values": False,
}
chart_labels = [
f"attribute accessing ({READ_WRITE_NUMBER})",
f"take snapshot ({STATES_QURING_TIME})",
f"states querying ({STATES_QURING_TIME})",
]
chart_data = [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]
i = 0
j = 0
for backend_name in ["static", "dynamic"]:
frame = build_frame(backend_name)
j = 0
for func, args in [
(attribute_access, READ_WRITE_NUMBER),
(take_snapshot, TAKE_SNAPSHOT_TIME),
(snapshot_query, STATES_QURING_TIME),
]:
t = func(frame, args)
chart_data[j][i] = t
j += 1
i += 1
tg.print_categories(["static", "dynamic"], chart_colors)
tg.chart(chart_colors, chart_data, chart_args, chart_labels)