
    h
                         S r SSKrSSKJr  SSKrSS\R
                  S\S\4S jjr SS\/ \R
                  4   S\S\4S	 jjr	SS\R
                  S\S\4S
 jjr
g)z_A collection of runtime performance bencharks, useful for debugging performance related issues.    N)Callableenvtarget_durationreturnc                    SnSnU R                  US9  U R                  R                  5         [        R                  " 5       n US-  nU R                  R                  5       nU R	                  U5      u    pxpU(       d  U	(       a  U R                  5         [        R                  " 5       U-
  U:  a  [        R                  " 5       nOM  XE-
  n
X:-  nU$ )a	  A benchmark to measure the runtime performance of step for an environment.

example usage:
    ```py
    env_old = ...
    old_throughput = benchmark_step(env_old)
    env_new = ...
    new_throughput = benchmark_step(env_old)
    slowdown = old_throughput / new_throughput
    ```

Args:
    env: the environment to benchmarked.
    target_duration: the duration of the benchmark in seconds (note: it will go slightly over it).
    seed: seeds the environment and action sampled.

Returns: the average steps per second.
r           seed   )resetaction_spacesampletimestep)r   r   r
   stepsendstartaction_terminal	truncatedlengthsteps_per_times               U/home/james-whalen/.local/lib/python3.13/site-packages/gymnasium/utils/performance.pybenchmark_stepr   	   s    & E
CII4IIIKE

!!((*'*xx'7$1	yIIK99;0))+C  [F^N    
env_lambdac                     SnSn[         R                   " 5       n US-  nU " 5       nUR                  US9  [         R                   " 5       U-
  U:  a  [         R                   " 5       nOMO  XE-
  nX7-  nU$ )a  A benchmark to measure the initialization time and first reset.

Args:
    env_lambda: the function to initialize the environment.
    target_duration: the duration of the benchmark in seconds (note: it will go slightly over it).
    seed: seeds the first reset of the environment.
r   r   r   r	   )r   r   )	r   r   r
   initsr   r   r   r   inits_per_times	            r   benchmark_initr!   4   sv     E
CIIKE

l		t	99;0))+C  [F^Nr   c                     SnSn[         R                   " 5       n US-  nU R                  5         [         R                   " 5       U-
  U:  a  [         R                   " 5       nOMI  X4-
  nX%-  nU$ )a  A benchmark to measure the time of render().

Note: does not work with `render_mode='human'`
Args:
    env: the environment to benchmarked (Note: must be renderable).
    target_duration: the duration of the benchmark in seconds (note: it will go slightly over it).

r   r   r   )r   render)r   r   rendersr   r   r   renders_per_times          r   benchmark_renderr&   O   sl     G
CIIKE
1

99;0))+C  [F'r   )   N)r'   )__doc__r   collections.abcr   	gymnasiumEnvintfloatr   r!   r&    r   r   <module>r/      s    e  $ (	 ( (u (X MQY]]*+>A
6)-- # e r   