Skip to main content

Conveniently get a rough idea of how long things take.

Project description

magic-timer

pip install magic-timer

A simple timer, for conveniently getting a rough idea of how long things take.

This is not for precision / accuracy; for that use something like timeit.

This package basically just makes timing with time.monotic() fractionally more convenient.

This package is not recommended for measuring sub 100 millisecond times.

Output is in an appropriate unit, rounded to two significant figures. Note that 3 digit numbers are also rounded to 2 sig figs, e.g. 231 -> 240.

Use via decorator:

from magic_timer import MagicTimer, magic_timer
import time

@magic_timer
def some_slow_function():
    time.sleep(2.75)

some_slow_function()
> 'some_slow_function' - 2.8 seconds

Use via MagicTimer object:

def some_slow_function():
    time.sleep(90/1000)

timer = MagicTimer()

some_slow_function()

print(timer)
> 95 milliseconds

See also this notebook.

The use case: you have a function you want to time, but you don't want to time it multiple times with timeit, and you don't want to use Jupyter %%timeit because %%timeit puts the cell into a different scope. You can import magic-timer, throw it on, and get a rough idea of the elapsed time.

This is somewhat of a pico-package...

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

magic-timer-0.0.11.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

magic_timer-0.0.11-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

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