A minimalist Python package to allow you to time different sections of your code.
Project description
Milestone Timer
A minimalist Python package to allow you to time different sections of your code.
Basic usage
Initialise a MilestoneTimer when you want the clock to start.
mt = MilestoneTimer()
Then add timing points in your code.
mt.add_milestone("Loaded config file")
Examples
import logging
from time import sleep
from milestone_timer import MilestoneTimer
log_format_string = "%(asctime)s | %(levelname)s | %(name)s | %(message)s"
logging.basicConfig(
level="DEBUG",
format=log_format_string,
)
logger = logging.getLogger(__name__)
mt = MilestoneTimer("Let's play!")
# Code here to meet the contestants
sleep(0.1)
logger.debug(mt.add_milestone("Met the contestants"))
# Code here to rotate the board
sleep(0.2)
logger.debug(mt.add_milestone("Rotated board"))
# Code here for numberwang
sleep(0.05)
logger.debug(mt.add_milestone("That's numberwang"))
print(mt) # Equivalently, `print(mt.milestones)`, this is the underlying dict
STDERR:
2024-06-22 20:00:30,433 | DEBUG | __main__ | Milestone 'Met the contestants' timed at 0.105 seconds
2024-06-22 20:00:30,635 | DEBUG | __main__ | Milestone 'Rotated board' timed at 0.202 seconds
2024-06-22 20:00:30,690 | DEBUG | __main__ | Milestone 'That's numberwang' timed at 0.055 seconds
STDOUT:
{"Let's play!": 17469.432649541, 'Met the contestants': 17469.537295625, 'Rotated board': 17469.739114875, "That's numberwang": 17469.794010833}
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
milestone_timer-1.0.0.tar.gz
(2.6 kB
view details)
Built Distribution
File details
Details for the file milestone_timer-1.0.0.tar.gz
.
File metadata
- Download URL: milestone_timer-1.0.0.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16151a3b9ebe2db6edf14972c03081d91feb37b873ed93388bd78f5c77da2726 |
|
MD5 | 0fcc2a1f9ebd7d3756e393905b670120 |
|
BLAKE2b-256 | 521fa12f811a246e49315c6094d70cc2f20f2a1b8dc053b791d1afdd9923f6f0 |
File details
Details for the file milestone_timer-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: milestone_timer-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9207f4154977b87ae9d63984f8674332e9737b564045814f84845b2a780f4bc2 |
|
MD5 | d2d9610dde0e1ad85862542068207499 |
|
BLAKE2b-256 | 9e5817986e25a29aaa444ffec81c22c51d539bf9dd21ad0a76ecbdcc0ef1df36 |