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 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file artimers-1.0.1.tar.gz.
File metadata
- Download URL: artimers-1.0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
164622c04b43c8a3d37e344eafd1fc39d2092bd94b1e8eab559349b6b5bed1a3
|
|
| MD5 |
23a12f76d3b1482de83872475cdf716a
|
|
| BLAKE2b-256 |
505b76590d76a947788747dfc84e1c1fddabb7c461b51588dff501d4a47fca96
|
File details
Details for the file artimers-1.0.1-py3-none-any.whl.
File metadata
- Download URL: artimers-1.0.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
427f83dbfaeb987a8edaf32bec6bc7c957efa210b137a81fec46506be4a9174e
|
|
| MD5 |
3026118a4273ef01f59345a097be176c
|
|
| BLAKE2b-256 |
0fe39d2e7f1a8669a831df57837182e5cab8fcd0c1c1f4427f01d1196280f10d
|