User Guide 👨🔧#
Timer for Python is a lightweight package and intended to be easy to use. A simple tool for measuring performance of Python programs or blocks of code.
Find tutorials and learn how get the most out of the Timer in this section.
Basic Usage and How to Wrap Your Code#
Manual Start and Stop#
After importing the Timer on top of your Python script, simply wrap the Timer function around your code to measure performance of the executed block of code:
Python | |
---|---|
After timer.stop()
, the elapsed time will be printed in the terminal:
Automatic Start and Stop#
Alternatively, use the with
statement for context management. This will automatically start and stop the clock – and so no need to declare timer.start()
and timer.stop()
. Same result as before, but less code:
How it appears in the terminal:
Decimals#
Set decimals to customise the precision of the terminal output:
How it appears in the terminal:
Multiple Threads#
There's total flexibility to measure the performance of different blocks of code using multiple threads:
Python | |
---|---|
How it appears in the terminal:
% Elapsed time: 0.12345 seconds for thread B
% Elapsed time: 6.78 seconds for thread A
Quick Links#
- Multiple threads to measure the performance of different blocks of code
- Decimals to set the precision of the terminal output
- Context manager to automatically start and stop the clock
- Function decorator to measure the performance of functions
- Humanised output to display time measurements in human-readable format
- Graceful error handling to gracefully handle exceptions and non-blocking code
Support the Project#
Become a Sponsor
If you find this project helpful, please consider supporting its development. Your donations will help keep it alive and growing. Every contribution, no matter the size, makes a difference.
Thank you for your support! 🙌