-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbench.py
More file actions
40 lines (35 loc) · 1.12 KB
/
bench.py
File metadata and controls
40 lines (35 loc) · 1.12 KB
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
import memory_gym
import gymnasium as gym
import time
import numpy as np
env = gym.make("SearingSpotlights-v0")
# env = gym.make("MortarMayhem-v0")
# env = gym.make("MysteryPath-v0")
# env = gym.make("MortarMayhemB-Grid-v0")
# env = gym.make("MysteryPath-Grid-v0")
def run():
fps_list = []
rew_list = []
for _ in range(1000):
steps = 0
start_time = time.time()
obs, reset_info = env.reset()
done = False
while not done:
obs, reward, done, truncation, info = env.step(env.action_space.sample())
steps += 1
fps = steps / (time.time() - start_time)
fps_list.append(fps)
rew_list.append(info["success"])
fps_list = np.array(fps_list)
print("Mean steps per second: " + str(np.mean(fps_list)) + " std: " + str(np.std(fps_list)))
rew_list = np.array(rew_list)
print("Mean reward: " + str(np.mean(rew_list)) + " std: " + str(np.std(rew_list)))
# import cProfile, pstats
# profiler = cProfile.Profile()
# profiler.enable()
run()
# profiler.disable()
# stats = pstats.Stats(profiler).sort_stats('cumtime')
# stats.print_stats()
env.close()