Skip to main content

A very simple python module for measuring time.

Project description

A very simple python module for measuring time. Github: https://github.com/astagi/lauda

Usage

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lauda-1.1.0.tar.gz (1.9 kB view details)

Uploaded Source

File details

Details for the file lauda-1.1.0.tar.gz.

File metadata

  • Download URL: lauda-1.1.0.tar.gz
  • Upload date:
  • Size: 1.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lauda-1.1.0.tar.gz
Algorithm Hash digest
SHA256 a34c21646ebcbdd4b7f88abecba7968b963b35fbf301fc343b3499b08c56e64b
MD5 98c14c14881118ec1d58dae631e53550
BLAKE2b-256 37c4bcf9dd484dbcea5361fee13f59478231b5d2f7ea795770281cbd333dcec4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page