lauda 1.2.0
A very simple python module for measuring time.
License: MIT
Keywords: time measurement

Lauda
=====

|Build Status| |Codecov.io Status| |Latest Version| |Supported Python
versions| |License| |Downloads|

A very simple python module for measuring time.

Install
-------

::

    pip install lauda

Usage
-----

You can use lauda ``StopWatch`` to measure the time spent in a portion
of code

.. code:: python

    from lauda import StopWatch

    watch = StopWatch()
    watch.start()
    for i in range(10000000):
        pass
    watch.stop()
    print ('Time spent in range {0}'.format(watch.elapsed_time))

You can also get the ``elapsed_time`` when the stopwatch is running

You can call checkpoint function if you want to set a checkpoint and get
the time spent between the last checkpoint:

.. code:: python

    from lauda import StopWatch

    watch = StopWatch()
    watch.start()
    for i in range(10000000):
        pass
    check_time = watch.checkpoint()
    print ('Time spent in first range: {0} sec.'.format(check_time))
    for i in range(10000000):
        pass
    check_time = watch.checkpoint()
    print ('Time spent in second range: {0} sec.'.format(check_time))

If you want to measure an entire function execution, you can decorate it
using the ``stopwatch`` decorator

.. code:: python

    from lauda import stopwatch

    @stopwatch
    def awesome_mul(a, b):
        return a * b

By default ``stopwatch`` decorator will print the time spent inside the
decorated function, if you want more control you can pass to your
decorator a callback that will receive a ``StopWatch`` instance and the
decorated function.

.. code:: python

    from lauda import stopwatch

    def stopwatch_sum_cb(watch, function):
        print ('Time spent {0}'.format(watch.elapsed_time))

    @stopwatch(callback=stopwatch_sum_cb)
    def awesome_sum(a, b):
        return a + b

If you want to measure a block of code, you can use the ``stopwatchcm``
context manager

.. code:: python

    from lauda import stopwatchcm

    with stopwatchcm():
        c = a * b

By default ``stopwatchcm`` context manager will print the time spent
inside the context manager body, if you want more control you can pass
to your context manager a callback that will receive a ``StopWatch``
instance.

.. code:: python

    from lauda import stopwatchcm

    def stopwatch_sum_cb(watch):
        print ('Time spent {0}'.format(watch.elapsed_time))

    with stopwatchcm(callback=stopwatch_sum_cb):
        c = a + b

.. |Build Status| image:: http://img.shields.io/travis/astagi/lauda.svg?branch=master
   :target: https://travis-ci.org/astagi/lauda
.. |Codecov.io Status| image:: https://img.shields.io/codecov/c/github/astagi/lauda.svg
   :target: http://codecov.io/github/astagi/lauda?branch=master
.. |Latest Version| image:: https://img.shields.io/pypi/v/lauda.svg
   :target: https://pypi.python.org/pypi/lauda/
.. |Supported Python versions| image:: https://img.shields.io/badge/python-2.6%2C%202.7%2C%203.3%2C%203.4-blue.svg
   :target: https://pypi.python.org/pypi/lauda/
.. |License| image:: https://img.shields.io/github/license/astagi/lauda.svg
   :target: https://pypi.python.org/pypi/lauda/
.. |Downloads| image:: https://img.shields.io/pypi/dm/lauda.svg
   :target: https://pypi.python.org/pypi/lauda/