benchmark.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python3
  2. import time
  3. import argparse
  4. import gym_minigrid
  5. import gym
  6. from gym_minigrid.wrappers import *
  7. parser = argparse.ArgumentParser()
  8. parser.add_argument(
  9. "--env-name",
  10. dest="env_name",
  11. help="gym environment to load",
  12. default='MiniGrid-LavaGapS7-v0'
  13. )
  14. parser.add_argument("--num_resets", default=200)
  15. parser.add_argument("--num_frames", default=5000)
  16. args = parser.parse_args()
  17. env = gym.make(args.env_name)
  18. # Benchmark env.reset
  19. t0 = time.time()
  20. for i in range(args.num_resets):
  21. env.reset()
  22. t1 = time.time()
  23. dt = t1 - t0
  24. reset_time = (1000 * dt) / args.num_resets
  25. # Benchmark rendering
  26. t0 = time.time()
  27. for i in range(args.num_frames):
  28. env.render('rgb_array')
  29. t1 = time.time()
  30. dt = t1 - t0
  31. frames_per_sec = args.num_frames / dt
  32. # Create an environment with an RGB agent observation
  33. env = gym.make(args.env_name)
  34. env = RGBImgPartialObsWrapper(env)
  35. env = ImgObsWrapper(env)
  36. # Benchmark rendering
  37. t0 = time.time()
  38. for i in range(args.num_frames):
  39. obs, reward, done, info = env.step(0)
  40. t1 = time.time()
  41. dt = t1 - t0
  42. agent_view_fps = args.num_frames / dt
  43. print('Env reset time: {:.1f} ms'.format(reset_time))
  44. print('Rendering FPS : {:.0f}'.format(frames_per_sec))
  45. print('Agent view FPS: {:.0f}'.format(agent_view_fps))