netket.utils.timing.Timer#
- class netket.utils.timing.Timer[source]#
Bases:
Pytree
Measures how much time was spent in a timer, with possible sub-timers.
Can be used as a context manager to time a scope, and will show up timers used inside of the scope if present.
If you directly construct a timer, you cannot nest it inside another timer. If you are building a library function you should instead use
netket.utils.timing.timed_scope()
.Example
Time a scope
>>> import netket as nk >>> import time >>> >>> with nk.utils.timing.Timer() as t: ... time.sleep(1) # This line and the ones below are indented ... with nk.utils.timing.timed_scope("subfunction 1"): ... time.sleep(0.5) ... with nk.utils.timing.timed_scope("subfunction 2"): ... time.sleep(0.25) >>> >>> t â•──────────────────────── Timing Information ─────────────────────────╮ │ Total: 1.763 │ │ ├── (28.7%) | subfunction 1 : 0.505 s │ │ └── (14.3%) | subfunction 2 : 0.252 s │ ╰─────────────────────────────────────────────────────────────────────╯
- Inheritance