Download tcod/trinity/utils/timer.py from SeanWang0027/ftb-sciworld-repro: direct link, hf CLI and curl.
- Browser
- Download file 431 Bytes
-
https://huggingface.co/SeanWang0027/ftb-sciworld-repro/resolve/main/tcod/trinity/utils/timer.py
- Command line
-
hf download hf://SeanWang0027/ftb-sciworld-repro/tcod/trinity/utils/timer.py
-
curl -L -o timer.py https://huggingface.co/SeanWang0027/ftb-sciworld-repro/resolve/main/tcod/trinity/utils/timer.py
431 Bytes
| """Timer context manager""" | |
| import time | |
| class Timer: | |
| def __init__(self, metrics_dict, key_name): | |
| self.metrics = metrics_dict | |
| self.key = key_name | |
| def __enter__(self): | |
| self.start_time = time.time() | |
| return self | |
| def __exit__(self, exc_type, exc_val, exc_tb): | |
| end_time = time.time() | |
| elapsed_time = end_time - self.start_time | |
| self.metrics[self.key] = elapsed_time | |