Metadata-Version: 2.1
Name: what2-time
Version: 0.3.0
Summary: Reusable timing code that handles unit conversion, pretty printing time, total of repeat and re-entrant timers.
Home-page: https://github.com/alwaysmpe/what2_time
License: MIT
Author: Marc Edwards
Author-email: marc@mlwhat.com
Requires-Python: >=3.12,<4.0
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Project-URL: Repository, https://github.com/alwaysmpe/what2_time
Description-Content-Type: text/markdown

# What 2 Time?

Reusable timing code that handles unit conversion,
pretty printing time, total of repeat and re-entrant timers.

A timer can be creted and will default to printing
total time on stopping:
```python
>>> from what2_time import Timer
>>> t = Timer().start()
>>> t.stop()
Elapsed time: 1.8890 seconds
```

Or given a name for ease of inspection
```python
>>> from what2_time import Timer
>>> t = Timer("FooTime").start()
>>> t.stop()
FooTime - Elapsed time: 1.4432 seconds
```

Alternatively, the output can be logged to
any callable such as a logger:
```python
>>> from what2_time import Timer
>>> import logging
>>> logger = logging.getLogger()
>>> logging.basicConfig(level=10)
>>> t = Timer(logger=logger.info).start()
>>> t.stop()
INFO:root:Elapsed time: 1.2577 seconds
```

Or instead set no logger handle logging yourself:
```python
>>> from what2_time import Timer
>>> t = Timer(logger=None).start()
>>> elapsed = t.stop()
>>> print(elapsed)
1.587853118
```

A timer can also be used as a context manager:
```python
>>> import time
>>> from what2_time import Timer
>>> with Timer("ContextTimer"):
...     time.sleep(1)
ContextTimer - Elapsed time: 1.0004 seconds
```

If you want to time the total time of something
that is not performed in a single block, instead
a `MetaTimer` can be used:
```python
>>> import time
>>> from what2_time import MetaTimer
>>> with MetaTimer("MetaT"):
...     time.sleep(1)
...
>>> with MetaTimer("MetaT"):
...     time.sleep(1)
...
>>> print(MetaTimer.get_meta_duration("MetaT"))
2.00162006
```

