Install
pip install tiner
Usage
Works like a context manager
from tiner import tiner
from time import sleep
with tiner("see this block"):
sleep(1)
# return the block running time
print(tiner.get('see this block'))
or as a python decorator
@tiner('see this function')
def f():
#do something
Global mining and grouping
the timing is managed by tiner, not its instances:
# A.py
for _ in range(20):
with tiner("t1"):
#do something
...
# B.py
for _ in range(20):
with tiner("t2"):
#do something
...
# main.py
tiner.table()
#-------------------------
╒═════════╤═══════════╤════════╕
│ Block │ Time(s) │ Hits │
╞═════════╪═══════════╪════════╡
│ t1 │ 0.026127 │ 20 │
├─────────┼───────────┼────────┤
│ t2 │ 0.0131467 │ 10 │
╘═════════╧═══════════╧════════╛
tiner internally records the different locations for the same block name, display the additional infomation with tiner.table(verbose=True):
for _ in range(10):
with tiner("test:loop"):
sleep(duration)
tiner.table(verbose=True)
#-------------------------
test:loop
╒═════════════════════╤════════╤═══════════╤════════╕
│ File │ Line │ Time(s) │ Hits │
╞═════════════════════╪════════╪═══════════╪════════╡
│ tests/test_tiner.py │ 107 │ 0.0128279 │ 10 │
├─────────────────────┼────────┼───────────┼────────┤
│ tests/test_tiner.py │ 112 │ 0.0132992 │ 10 │
╘═════════════════════╧════════╧═══════════╧════════╛
Design for loops
from tiner import tiner
from time import sleep
for _ in range(10):
#do something
with tiner("see this loop"):
sleep(0.1)
#do something
# return the block running time over the loops
print(tiner.get('see this loop'))
Handle asynchronous programs
import os
from tiner import tiner
# tiner will call the synchronize function when the block is over
with tiner("loop", synchronize=torch.cuda.synchronize):
# machine learning running
# return the block running time over the loops
print(tiner.get('loop'))
Easy to use
A timer should be clear and simple
tiner.get(BLOCK_NAME) # return a certain block running time so far
tiner.table([BLOCK1, ...]) # print some blocks' time on a formatted table
tiner.zero([BLOCK1, ...]) # empty some blocks' time
tiner.disable() # disable time logging
tiner.enable() # enable time logging
NOTE:
tiner's timing is relatively precise. You should only use it for comparison of the timings of different blocks in one run, not for different runs of your program.
Metadata
Release files for tiner 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tiner-0.0.8.tar.gz | 4.9 kB | Without provenance | Details for tiner-0.0.8.tar.gz |
Release files / tiner-0.0.8.tar.gz
| Download URL | tiner-0.0.8.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c768bd65827eab6d8339f8a0ad626f6ae7e5b414004a21b9c0e7d62a9acf0792
|
|
BLAKE2b-256 checksum How to use checksums |
5c8eff8786f47546a705aafcc042fc74bc3c0dc9c2f61219f10ca747266e8124
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Security for tiner 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.