Timer for Python ⏳#
Introduction#
Performance timing made easy. When you want to measure how much time it takes to run Python programs and gauge performance of multiple blocks of code, Timer for Python is a lightweight Python package that gets the job done.
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:
Ready to try? Let's get started.