forked from minetest/minetest
-
Notifications
You must be signed in to change notification settings - Fork 10
/
measure_fps.py
executable file
·66 lines (59 loc) · 1.52 KB
/
measure_fps.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
#!/usr/bin/env python3
import time
import matplotlib.pyplot as plt
import numpy as np
from minetester.minetest_env import Minetest
headless = True
render = False
sync = True
sync_port = 30010
sync_dtime = 0.05
undersampling = 1
env = Minetest(
seed=42,
start_minetest=True,
xvfb_headless=headless,
sync_port=sync_port,
sync_dtime=sync_dtime,
config_dict=dict(undersampling=undersampling),
)
obs = env.reset()
tot_time = 0
time_list = []
fps_list = []
step = 0
while True:
start = time.time()
try:
action = env.action_space.sample()
obs, rew, done, info = env.step(action)
if render:
env.render()
dtime = time.time() - start
tot_time += dtime
fps = 1/dtime
time_list.append(tot_time)
fps_list.append(fps)
step += 1
except KeyboardInterrupt:
break
env.close()
# Print stats
fps_np = np.array(fps_list)
print(f"Runtime = {tot_time:.2f}s")
print(f"Avg. FPS = {fps_np.mean():.2f}, Min. FPS = {fps_np.min():.2f}, Max. FPS = {fps_np.max():.2f}")
# Plot FPS over time
plt.figure()
plt.plot(time_list, fps_list, label="data")
# Calculate moving average
window = int(len(fps_list) * 0.1) + 1
mav = np.convolve(fps_np, np.ones(window) / window, mode="same")
plt.plot(time_list, mav, label="moving avg.")
plt.xlabel("time [s]")
plt.ylabel("FPS")
plt.legend()
if sync:
plt.savefig(f"fps_testloop_sync_{'headless_' if headless else ''}.png")
else:
plt.savefig(f"fps_testloop_async_{'headless' if headless else ''}.png")
plt.show()