Skip to main content

A utility package for timing and managing timers.

Project description

artimers

A utility package for timing and managing timers by Alexander Rießbeck

The goal of this package is it to provide easy to use timers that can collect timing data across your project and make the collected times accessible.

$ python -m pip install TBD:artimers

Usage

from artimers import Timer

Basics

Timer can be used in multiple ways

Class

Timer can be used as a class

timer = Timer()
timer.start()
...
final_time = timer.stop()

Decorator

Timer can be used as a decorator

@(timer:=Timer())
def foo():
    ...

print(timer)

Context Manager

Timer can be used as a context manager

with Timer() as timer:
    ...
    x = timer.time

Pretty print

Timer also has a custom __str__ method

timer = Timer()
timer.start()
sleep(0.2)
print(timer)
sleep(0.2)
timer.stop()
print(timer)
Timer (Running): 0.2004s
Timer (Stopped): 0.4007s

If the timer is named (Timer('Stopwatch 1')) the name will be used instead of Timer.

Printed decimals

The deciaml point used in the __str__ function can also be set (default is 4 and timing seems to be accurate up to 2)

timer = Timer(decimal=5)
print(timer)

Naming

Timer can be named and easily accessed later by using the same name again

Timer('Stopwatch 1')
Timer(name='Stopwatch 2')

Named timers always return the same instance and therefore keep their time and status (Running/Stopped).

Get timers

Timer can return a dict of all named timers

named_timers = Timer.get_timers()

Print results

The final time can be printed when exiting a decorator or context manager

@(Timer(print_result=True))
def foo():
    ...
with Timer(print_result=True):
    ...

Return results

The final time can also be return from a decorated function

@(Timer(return_result=True))
def foo():
    ...

time, _ = foo()

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

artimers-1.0.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

artimers-1.0.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file artimers-1.0.0.tar.gz.

File metadata

  • Download URL: artimers-1.0.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for artimers-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b45b36d80ab1c0f474660752ad11af2216aee78f836c691a4ade0e256a5ff76b
MD5 af9382e24467054f789e29a24a6700b5
BLAKE2b-256 6f894c83529cba879872734f25294358ed47500cb3d012d140fec68c5782a0cf

See more details on using hashes here.

File details

Details for the file artimers-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: artimers-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for artimers-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea2efa0da7c801a52ac71b1130dbd1ff21d0995981686c9837ae531a6cf2c36e
MD5 962baa69b3bd660edb977f4e9eca7f0a
BLAKE2b-256 eb7d11c8bbc69c213e6509074d1a1fa5907574f14ad46e476f8f6ed5bef0daca

See more details on using hashes here.

Supported by

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