
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
A versatile and easy-to-use Python timer utility for measuring code execution time and analyzing performance.
Install Todd's Timer using pip:
pip install todds_timer
At the top of your python file, import the Timer class and configure logging.
Standard timing messages are logged at the DEBUG level, however the summary table
produced by print_average_times()
is at the INFO level.
from todds_timer import Timer
import logging
logging.basicConfig(level=logging.DEBUG, format="%(levelname)s %(message)s")
with Timer("Calculating sum"):
result = sum([1,2,3,4])
Output:
DEBUG ----STARTED Calculating sum
DEBUG ----COMPLETED (in 0.000 seconds) Calculating sum
@Timer("Calculate sum of {0} and {1}")
def add_numbers(a, b):
return a + b
result = add_numbers(5, 7)
Output:
DEBUG ----STARTED Calculate sum of 5 and 7
DEBUG ----COMPLETED (in 0.000 seconds) Calculate sum of 5 and 7
with Timer("Outer operation"):
# Some code here
with Timer("Inner operation"):
# More code here
pass
Output:
DEBUG ----STARTED Outer operation
DEBUG --------STARTED Inner operation
DEBUG --------COMPLETED (in 0.000 seconds) Inner operation
DEBUG ----COMPLETED (in 0.000 seconds) Outer operation
# After running some timed operations
Timer.print_average_times(sort="name")
Output:
INFO Average | Minimum | Maximum | Count | Task name
INFO 0.000 | 0.000 | 0.000 | 1 | Calculate sum of 5 and 7
INFO 0.000 | 0.000 | 0.000 | 1 | Calculating sum
INFO 0.000 | 0.000 | 0.000 | 1 | Inner operation
INFO 0.000 | 0.000 | 0.000 | 1 | Outer operation
Todd's Timer uses Python's built-in logging
module. To see the timing output, ensure that your logging is configured to show DEBUG level messages:
import logging
logging.basicConfig(level=logging.DEBUG)
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
A custom timer utility for Python
We found that todds-timer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.