-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbenchmark.py
106 lines (84 loc) · 2.93 KB
/
benchmark.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
import sys
import time
class BaseBenchmark:
def __init__(self, name):
self.name = name
def get_mem_usage(self):
return "", ""
def setup(self, num_entities, num_components): # pylint: disable=unused-argument
return 0
def update_cold(self):
return 0
def update_warm(self):
return 0
def run(self):
print('={}='.format(self.name))
print('==Memory==')
print('Entity: {}, NullComponent: {}'.format(
*self.get_mem_usage()
))
print()
print('==Time==')
incs = [1, 100, 1000]
for num_ent in incs:
for num_comp in incs:
print('Entities: {}, Components: {}'.format(num_ent, num_comp))
time_start = time.perf_counter_ns()
self.setup(num_ent, num_comp)
time_setup = (time.perf_counter_ns() - time_start) / 100_000
time_start = time.perf_counter_ns()
self.update_cold()
time_update_cold = (time.perf_counter_ns() - time_start) / 100_000
time_start = time.perf_counter_ns()
self.update_warm()
time_update_warm = (time.perf_counter_ns() - time_start) / 100_000
time_total = time_setup + time_update_cold + time_update_warm
print('\t{:0.2f}ms (setup: {:0.2f}ms, cold update: {:0.2f}ms, warm update: {:0.2f}ms)'.format(
time_total,
time_setup,
time_update_cold,
time_update_warm,
))
class SimpleEcsBench(BaseBenchmark):
def __init__(self):
import simpleecs
import simpleecs.components
self.component_classes = [
type(
'NullComponent{}'.format(i),
simpleecs.components.NullComponent.__bases__,
dict(simpleecs.components.NullComponent.__dict__),
)
for i in range(10_000)
]
self.world = None
super().__init__('simpleecs')
def get_mem_usage(self):
import simpleecs
import simpleecs.components
return (
sys.getsizeof(simpleecs.World().create_entity()),
sys.getsizeof(simpleecs.components.NullComponent())
)
def setup(self, num_entities, num_components):
import simpleecs
import simpleecs.systems
self.world = simpleecs.World()
self.world.add_system(
simpleecs.systems.NullSystem(),
)
for _ in range(num_entities):
self.world.create_entity([
self.component_classes[compnum]
for compnum in range(num_components)
])
def update_cold(self):
self.world.update(0)
def update_warm(self):
self.world.update(0)
if __name__ == '__main__':
BENCHMARKS = [
SimpleEcsBench()
]
for bench in BENCHMARKS:
bench.run()