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


Groups > comp.lang.python.announce > #1914

ANN lauda 1.2.0

From Andrea Stagi <stagi.andrea@gmail.com>
Newsgroups comp.lang.python.announce
Subject ANN lauda 1.2.0
Date 2015-11-04 10:17 +0100
Message-ID <mailman.7.1446628706.16136.python-announce-list@python.org> (permalink)

Show all headers | View raw


I've released lauda 1.2.0 https://github.com/astagi/lauda/releases/tag/1.2.0,
a little python module to measure time. You can install it using

    pip install lauda

The source code is 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))

In the new versionm you can also get the "elapsed_time" when the stopwatch
is running, also you can call checkpoint function if you want to set a
checkpoint and get the time spent between the last checkpoint:

    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

    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


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

Back to comp.lang.python.announce | Previous | Next | Find similar | Unroll thread


Thread

ANN lauda 1.2.0 Andrea Stagi <stagi.andrea@gmail.com> - 2015-11-04 10:17 +0100

csiph-web