|
| 1 | +import math |
1 | 2 | from unittest.mock import patch |
2 | 3 |
|
3 | 4 | import pytest |
|
6 | 7 |
|
7 | 8 | import genesis as gs |
8 | 9 | import genesis.utils.geom as gu |
| 10 | +from genesis.utils.tools import FPSTracker |
9 | 11 | from genesis.utils.misc import tensor_to_array |
10 | 12 | from genesis.utils import warnings as warnings_mod |
11 | 13 | from genesis.utils.warnings import warn_once |
@@ -404,3 +406,29 @@ def test_pyrender_vec3(): |
404 | 406 | tq = qz.as_tensor() |
405 | 407 | assert isinstance(tq, torch.Tensor) |
406 | 408 | assert_allclose(tq.cpu().numpy(), qz.v, tol=gs.EPS) |
| 409 | + |
| 410 | + |
| 411 | +def test_fps_tracker(): |
| 412 | + n_envs = 23 |
| 413 | + tracker = FPSTracker(alpha=0, n_envs=n_envs) |
| 414 | + tracker.step(current_time=10.0) |
| 415 | + assert not tracker.step(current_time=10.0) |
| 416 | + assert not tracker.step(current_time=10.0) |
| 417 | + assert not tracker.step(current_time=10.0) |
| 418 | + fps = tracker.step(current_time=10.2) |
| 419 | + # num envs * [num steps] / (delta time) |
| 420 | + assert math.isclose(fps, n_envs * 4 / 0.2) |
| 421 | + |
| 422 | + assert not tracker.step(current_time=10.21) |
| 423 | + assert not tracker.step(current_time=10.22) |
| 424 | + assert not tracker.step(current_time=10.29) |
| 425 | + fps = tracker.step(current_time=10.31) |
| 426 | + # num envs * [num steps] / (delta time) |
| 427 | + assert math.isclose(fps, n_envs * 4 / 0.11) |
| 428 | + |
| 429 | + assert not tracker.step(current_time=10.33) |
| 430 | + assert not tracker.step(current_time=10.37) |
| 431 | + assert not tracker.step(current_time=10.39) |
| 432 | + fps = tracker.step(current_time=10.45) |
| 433 | + # num envs * [num steps] / (delta time) |
| 434 | + assert math.isclose(fps, n_envs * 4 / 0.14) |
0 commit comments