File size: 1,301 Bytes
406662d | 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 41 42 | # Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
# NOTE: While we don't actually use the simulation app in this test, we still need to launch it
# because warp is only available in the context of a running simulation
"""Launch Isaac Sim Simulator first."""
from isaaclab.app import AppLauncher
# launch omniverse app
simulation_app = AppLauncher(headless=True).app
"""Rest everything follows."""
import time
from isaaclab.utils.timer import Timer
# number of decimal places to check
PRECISION_PLACES = 2
def test_timer_as_object():
"""Test using a `Timer` as a regular object."""
timer = Timer()
timer.start()
assert abs(0 - timer.time_elapsed) < 10 ** (-PRECISION_PLACES)
time.sleep(1)
assert abs(1 - timer.time_elapsed) < 10 ** (-PRECISION_PLACES)
timer.stop()
assert abs(1 - timer.total_run_time) < 10 ** (-PRECISION_PLACES)
def test_timer_as_context_manager():
"""Test using a `Timer` as a context manager."""
with Timer() as timer:
assert abs(0 - timer.time_elapsed) < 10 ** (-PRECISION_PLACES)
time.sleep(1)
assert abs(1 - timer.time_elapsed) < 10 ** (-PRECISION_PLACES)
|