Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python.announce > #1859 > unrolled thread

ANN lauda 1.1.0

Started byAndrea Stagi <stagi.andrea@gmail.com>
First post2015-09-16 12:19 +0200
Last post2015-09-16 12:19 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python.announce


Contents

  ANN lauda 1.1.0 Andrea Stagi <stagi.andrea@gmail.com> - 2015-09-16 12:19 +0200

#1859 — ANN lauda 1.1.0

FromAndrea Stagi <stagi.andrea@gmail.com>
Date2015-09-16 12:19 +0200
SubjectANN lauda 1.1.0
Message-ID<mailman.629.1442399067.8327.python-announce-list@python.org>
I've created lauda, a little python module to measure time. Thanks a lot to
Jesús Espino (@jespinog) for the new context manager feature

You can install it with

    pip install lauda

you can find the source code on Github: https://github.com/astagi/lauda

You can use lauda StopWatch to measure a portion of code

    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))

If you want to measure an entire function execution, you can decorate it
using the stopwatch decorator

    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.

    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

    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.

    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

-- 
Andrea Stagi (@4stagi) - Develover @Nephila
Job profile: http://linkedin.com/in/andreastagi
Website: http://4spills.blogspot.it/
Github: http://github.com/astagi

[toc] | [standalone]


Back to top | Article view | comp.lang.python.announce


csiph-web