Table of Contents

Class Performance

Namespace
Gym.Utils
Assembly
Gym.dll

Runtime benchmarks for finding performance problems (Gymnasium's gymnasium.utils.performance): how many steps, vector steps, constructions or renders an env manages per second over a target duration. Each runs until the clock passes the target, so it runs slightly over it, and reports the count divided by the time measured.

public static class Performance
Inheritance
Performance
Inherited Members

Remarks

The clock is Time, Python's time.time() by default; Gymnasium's tests replace time.time to script the timestamps, and Gym.NET's replace Time the same way (a process-wide setting: restore it afterwards). Unlike Python, the benchmarks dispose what they drop (the samples, observations and frames), so the garbage collector's work does not leak into the measurement.

Reference: gymnasium/utils/performance.py.

Properties

Time

The clock in seconds (Python's time.time(), wall-clock seconds since the Unix epoch); replaceable, as Gymnasium's tests monkeypatch performance.time.time. Process-wide: a test that replaces it restores it.

public static Func<double> Time { get; set; }

Property Value

Func<double>

Methods

BenchmarkInit(Func<IEnv>, double, BigInteger?)

Measures construction and first reset (benchmark_init): builds an env with envLambda and resets it, again and again, until targetDuration seconds passed.

public static double BenchmarkInit(Func<IEnv> envLambda, double targetDuration = 5, BigInteger? seed = null)

Parameters

envLambda Func<IEnv>

Builds an env; each is disposed after its reset (Python leaves them to the garbage collector).

targetDuration double

The duration in seconds; the benchmark goes slightly over it.

seed BigInteger?

The seed of each first reset.

Returns

double

The constructions per second.

Exceptions

ArgumentNullException

Thrown when envLambda is null.

ZeroDivisionError

Thrown when no time passed, as Python's float division by zero.

BenchmarkRender(IEnv, double)

Measures render() (benchmark_render): renders again and again until targetDuration seconds passed.

public static double BenchmarkRender(IEnv env, double targetDuration = 5)

Parameters

env IEnv

The env, built with a render mode that returns frames (not human, as in Gymnasium).

targetDuration double

The duration in seconds; the benchmark goes slightly over it.

Returns

double

The renders per second.

Exceptions

ArgumentNullException

Thrown when env is null.

ZeroDivisionError

Thrown when no time passed, as Python's float division by zero.

BenchmarkStep(IEnv, double, BigInteger?)

Measures the step throughput of an env (benchmark_step): resets with seed, then steps with sampled actions (resetting at every episode end) until targetDuration seconds passed.

public static double BenchmarkStep(IEnv env, double targetDuration = 5, BigInteger? seed = null)

Parameters

env IEnv

The env; its action space is sampled once before the clock starts, as Gymnasium does.

targetDuration double

The duration in seconds; the benchmark goes slightly over it.

seed BigInteger?

The first reset's seed (the action space is not seeded, as in Gymnasium).

Returns

double

The average steps per second.

Exceptions

ArgumentNullException

Thrown when env is null.

ZeroDivisionError

Thrown when no time passed (a negative target), as Python's float division by zero.

BenchmarkVectorStep(IVectorEnv, double, BigInteger?)

Measures the step throughput of a vector env in sub-env steps per second (benchmark_vector_step): seeds the action space, resets, takes one warm-up step outside the measurement and resets again, then steps until targetDuration seconds passed. Under NEXT_STEP the steps that only reset a sub-env do not count; under DISABLED the ended sub-envs are reset through reset_mask.

public static double BenchmarkVectorStep(IVectorEnv env, double targetDuration = 5, BigInteger? seed = null)

Parameters

env IVectorEnv

The vector env.

targetDuration double

The duration in seconds; the benchmark can run longer while its last step completes.

seed BigInteger?

The seed of the action space and of both resets.

Returns

double

The number of individual environment steps per second.

Exceptions

ArgumentNullException

Thrown when env is null.

ZeroDivisionError

Thrown when no time passed, as Python's float division by zero.