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.
Readme
Python code timer, support block wise and function wise
pip install timer
import
from timer import timer
decorate without brackets
@timer
def func(): ...
decorate with brackets
@timer()
def func(): ...
decorate with name and time unit
@timer('function name', 's')
def func(): ...
decorate with key word arguments
@timer(name='function name', unit='s')
def func(): ...
block wise without object
with timer():
...
block wise with object
with timer() as t:
...
print(t.elapse)
import logging
import time
from timer import timer, get_timer
# default timer's logging level is logging.DEBUG
# so timer would print nothing if logging level is logging.INFO or higher
logging.basicConfig(level=logging.DEBUG)
# or you can change default timer's logging level
timer.set_level(logging.DEBUG)
# also you can get a timer with custom logging level with get_timer(level)
warning_timer = get_timer(logging.WARNING)
# explicit the timer's name and it's time unit
@timer('function:add', unit='s')
def add(a, b):
time.sleep(.1)
return a + b
# function name is timer's name for default
@timer
def sub(a, b):
time.sleep(.1)
return a - b
if __name__ == '__main__':
# 'timer' would be timer's name by default
with timer('time.sleep(2)') as t:
print(3)
time.sleep(1)
print(f'after time.sleep(1) once, t.elapse = {t.elapse}')
time.sleep(1)
print(f'after time.sleep(1) twice, t.elapse = {t.elapse}')
print(f'after with, t.elapse = {t.elapse}')
with warning_timer('test'):
pass
print(add(1, 1))
print(sub(2, 1))
3
after time.sleep(1) once, t.elapse = 1.003798776
after time.sleep(1) twice, t.elapse = 2.0052743459999998
DEBUG:timer.time.sleep(2): 2.006 s
after with, t.elapse = 2.005628447
WARNING:timer.test:start
WARNING:timer.test:cost 0 ms
DEBUG:timer.function:add: 0.105 s
2
DEBUG:timer.sub: 102 ms
1
FAQs
Python Code Timer
We found that timer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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.