pydu/docs/dt.md

27 lines
650 B
Markdown
Raw Normal View History

2018-04-22 12:55:40 +00:00
Date and Time
-------------
Utils for handling date and time.
.. py:class:: pydu.dt.timer(path)
A timer can time how long does calling take as a context manager or decorator.
If assign ``print_func`` with ``sys.stdout.write``, ``logger.info`` and so on,
timer will print the spent time.
timeit = timer(print_func=sys.stdout.write)
with timeit:
foo()
@timeit
def foo():
pass
``timer.elapsed`` contains the total amount of elapsed
time of running ``foo``.
>>> timeit = timer(print_func=sys.stdout.write)
>>> with timeit:
... os.getcwd()
Spent time: 1.7881393432617188e-05s