-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_physics.py
67 lines (60 loc) · 2.02 KB
/
benchmark_physics.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
import random
import time
import numpy as np
import scoping_simulations.utils.matter_server as Matter_Server
from scoping_simulations.utils.blockworld import Blockworld
N = 100
print("Benchmarking Box2D")
w = Blockworld(silhouette=np.ones((8, 8)), physics_provider="box2d")
start_time = time.time()
num_actions = 0
times = []
for i in range(N):
for j in range(5):
# take random action
actions = w.current_state.possible_actions()
try:
action = random.choice(actions)
num_actions += 1
except:
break
w.apply_action(action)
start_time = time.time()
stable = w.stability()
end_time = time.time()
# print("stability {},{} in {} milliseconds: {}".format(
# i, j, (end_time - start_time)*1000,stable))
times.append(end_time - start_time)
w.reset()
# print("Box2D: %s seconds" % (time.time() - start_time)," #actions:",num_actions)
print("mean time for Box2D physics server:", np.mean(times) * 1000, "milliseconds")
# or to create a server
physics_provider = Matter_Server.Physics_Server()
print("Physics provider created")
print("Benchmarking matter")
w = Blockworld(silhouette=np.ones((8, 8)), physics_provider=physics_provider)
start_time = time.time()
num_actions = 0
times = []
for i in range(N):
# print(i)
for j in range(5):
# take random action
actions = w.current_state.possible_actions()
try:
action = random.choice(actions)
num_actions += 1
except:
break
w.apply_action(action)
start_time = time.time()
stable = w.stability()
end_time = time.time()
# print("stability {},{} in {} milliseconds: {}".format(
# i, j, (end_time - start_time)*1000,stable))
times.append(end_time - start_time)
w.reset()
# print("matter: %s seconds" % (time.time() - start_time)," #actions:",num_actions)
print("mean time for matter physics server:", np.mean(times) * 1000, "milliseconds")
w.__del__()
print("Done")