Skip to main content

Conveniently get a rough idea of how long things take.

Project description

magic-timer

pip install magic-timer

Conveniently get a rough idea of how long things take.

This is a light wrapper around the standard library's time.monotonic.

How to use:

Use via context manager:

from magic_timer import MagicTimer

with MagicTimer() as timer:
    x = sum(i*i for i in range(100_000))  # do stuff

# Print a nicely formatted string:
print('Stuff took', timer)

# Or get the elapsed time in seconds:
time_elapsed = timer.time_elapsed()
print(time_elapsed)
> Stuff took 8.0 milliseconds
> 0.007906290999997623

Use via MagicTimer object:

from magic_timer import MagicTimer

def do_stuff():
    [i*i for i in range(5_000_000)]

timer = MagicTimer()
do_stuff()
print('Stuff took', timer)
> Stuff took 455 milliseconds

To "freeze" the timer, use the stop method:

from magic_timer import MagicTimer

def do_stuff():
    [i*i for i in range(5_000_000)]

timer = MagicTimer()
do_stuff()
timer.stop()
print('Stuff took', timer)
time_elapsed = timer.time_elapsed()

Use via ftimer decorator:

from magic_timer import ftimer

@ftimer
def do_stuff():
    [i*i for i in range(20_000_000)]

do_stuff()
> `do_stuff` ran in 1.9 seconds.

The use case for this package:

You have something you want to time, but you don't want to time it multiple times with timeit.

You also don't want to use Jupyter's %%timeit because it puts the cell into a different scope.

You can import magic-timer, throw it in, and get a rough idea of the time taken. (It's slightly neater than using time.monotonic directly.)

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.2.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

magic_timer-0.2.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file magic-timer-0.2.1.tar.gz.

File metadata

  • Download URL: magic-timer-0.2.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 CPython/3.9.2

File hashes

Hashes for magic-timer-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f5c758fed218c540e009967bc4522b8919091fc63f116989bbe9d26ea954494d
MD5 a521d06e2529cbd0a998dcc7480d74d2
BLAKE2b-256 b12a1474bc38e40b86f8df2954b59a69ecd05d1cb6b12f8d0cea9531575b0c52

See more details on using hashes here.

File details

Details for the file magic_timer-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: magic_timer-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 CPython/3.9.2

File hashes

Hashes for magic_timer-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1a438bb27516dfe0f988c48219cd373385e0138de1ad435d154055e5cea6fef4
MD5 cd40065740e4bdad4ba0ce1e86a155b5
BLAKE2b-256 b21a1e9c3e82b476fc906122a060261b107c67b6ac023f335ef2f94de5f600b5

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