Skip to main content

Block-wise timer for Python

Project description

tiner

Block-wise timer for Python

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'))

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'))

Global mining

the timing is managed by tiner, not its instances

# A.py
with tiner("In A"):
  #do something
...
# B.py
with tiner("In B"):
  #do something

tiner.table()
╒═════════╤═══════════╕
│ Block   │   Time(s) │
╞═════════╪═══════════╡
│ In B    │  ...      │
├─────────┼───────────┤
│ In A    │  ...      │
╘═════════╧═══════════╛

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

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.

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

tiner-0.0.5.tar.gz (4.1 kB view hashes)

Uploaded Source

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