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:

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()
timer.stop()
print('Stuff took', timer)
> Stuff took 455 milliseconds

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

Uploaded Source

Built Distribution

magic_timer-0.2.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: magic-timer-0.2.0.tar.gz
  • Upload date:
  • Size: 3.8 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.0.tar.gz
Algorithm Hash digest
SHA256 d990269d3877087c8946cd69742ae17d9bcda76e6bc1b585f37f20dd1e4a35cd
MD5 25c5a968a91405ceaa2bb574e1b9a1fe
BLAKE2b-256 d4709e3a7a6dd0a71ff9d33637008667c7fa91f5b03d281f11e6e06b9d4d3e20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: magic_timer-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4496336093657d6e0caead5b093f7001e5d5452176fcf2889a5c1b961715a7c
MD5 ccb0f6a6b5cda49c498bca8337406b8d
BLAKE2b-256 a735834ecf5247836c1e19319473390212f2838c0e0a7ced450dcb6bb5096aa5

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