Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
timer-for-python
Readme
Lightweight Python package that makes it easy to measure how much time it takes to run Python programs and gauge performance of multiple, smaller bits of code.
Ready to try? Learn how to install and find tutorials in the user guide.
Simply add the Timer to your imports, and then wrap the Timer function around your code to measure the performance of the executed block of code:
from timer import Timer
timer = Timer()
timer.start()
# Insert your code here
timer.stop() # Output example: 12.34 seconds
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:
with Timer():
# Insert your code here
# Output example: 12.34 seconds
Or use the benchmark_timer
as a function decorator:
from timer import benchmark_timer
@benchmark_timer
def test_function():
# Insert your code here
test_function()
# Output example: 12.34 seconds for thread TEST_FUNCTION
Instead of the default value of 2
for decimals``, you can set the output precision up to
9in the
decimals` argument:
timer = Timer()
timer.start(decimals=5)
# Insert your code here
timer.stop() # Output example: 0.12345 seconds
Imagine that you want to troubleshoot which parts of your code are performing better or worse. Or do you want to split-test the performance of different methods? Timer for Python is a quick, easy way to get the job done.
To measure the performance of multiple blocks of code, use the thread
argument to name different threads:
timer = Timer()
timer.start(thread="A")
# Insert your code here
timer.start(thread="B", decimals=5)
# Insert more code here
timer.stop(thread="B") # Output example: 0.12345 seconds for thread B
# Insert even more code here
timer.stop(thread="A") # Output example: 6.78 seconds for thread A
Or use the with
statement to get the same result with less code:
with Timer(thread="A")
# Insert your code here
with Timer(thread="B", decimals=5):
# Insert more code here
# Output example: 0.12345 seconds for thread B
# Insert even more code here
# Output example: 6.78 seconds for thread A
This module is free to use. And if you like it, feel free to buy me a coffee.
If you have suggestions or changes to the module, feel free to add to the code and create a pull request.
Report bugs and issues here.
Copyright (c) 2020 – present, Jakob Bagterp
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Timer for Python
We found that timer-for-python 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.