Timer for Python ⏳#
Why Use a Timer?#
Measuring time and performance should be easy. If you want to measure the time it takes to run Python programs and measure the performance of multiple blocks of code, Timer for Python is a lightweight package that does the job.
How It Works#
Basics#
Simply wrap the Timer around a block of code that you want to measure:
Python | |
---|---|
After timer.stop()
, the elapsed time will be printed in your terminal. Example:
Context Manager#
Alternatively, use the with
statement. This will automatically start and stop the Timer – and so no need to declare timer.start()
and timer.stop()
. Same result as before, but less code:
Terminal output example:
Function Decorator#
Or use @benchmark_timer
as function decorator:
Python | |
---|---|
Terminal output example:
Next Steps#
Ready to try? Let's get started.
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! 🙌