![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Readme
Time execution of blocks of code.
Tested against python 3.6, python 3.7, and 3.8
From pip
pip install ttictoc
or download this repo and do
pip install .
The easiest way to time something is with tic
and toc
import time
from ttictoc import tic,toc
tic()
time.sleep(1)
elapsed = toc()
print('Elapsed time:',elapsed)
You can execute multiple tocs in a matlab-like fashon
import time
from ttictoc import tic,toc
tic()
for i in range(2):
tic()
time.sleep(1)
elapsed = toc()
print('[IN LOOP] Elapsed time:',elapsed)
print('[OUT LOOP] Elapsed time:',toc())
It works just like tic
,toc
.
import time
from ttictoc import Timer
# Simple
t = Timer()
t.start()
time.sleep(1)
elapsed = t.stop()
print('Elapsed time:',elapsed)
# Nested
t.start()
for i in range(2):
t.start()
time.sleep(1)
elapsed = t.stop()
print('[IN LOOP] Elapsed time:',elapsed)
print('[OUT LOOP] Elapsed time:',t.stop())
You can also use it as context manager
import time
from ttictoc import Timer
# Default
with Timer():
time.sleep(1)
# With out verbose
with Timer(verbose=False) as T:
time.sleep(1)
print('Elapsed time:',T.elapsed)
# With default verbose message
with Timer(verbose_msg=f'[User msg][{time.time()}] Elapsed time: {{}}'):
time.sleep(1)
You can deactivate the matlab-like nesting. In this case calling start will update the global starting time for toc. However, you can have nested tics by giving a key
to start and stop.
import time
from ttictoc import Timer,tic2,toc2
tic2()
for i in range(2):
tic2()
time.sleep(1)
elapsed = toc2()
print('[IN LOOP] Elapsed time:',elapsed)
print('[OUT LOOP] Elapsed time:',toc2())
t = Timer(matlab_like=False)
t.start()
time.sleep(1)
t.start() # Restarts the starting point
time.sleep(1)
elapsed = t.stop()
print('Elapsed time:',elapsed) # ~1 second
# Nested
t.start(key='Init')
for i in range(2):
t.start(key=i)
time.sleep(1)
elapsed = t.stop(key=i)
print('[IN LOOP] Elapsed time:',elapsed)
print('[OUT LOOP] Elapsed time:',t.stop('Init'))
print('\n[OUT LOOP][Init] Elapsed time:',t.stop('Init'))
print('[OUT LOOP][0] Elapsed time:',t.stop(0))
print('[OUT LOOP][1] Elapsed time:',t.stop(1))
By default, Timer
(and tic
,toc
) use timeit.default_timer
. However, the timing function can be selected as follow.
import time
from ttictoc import Timer
t = Timer(func_time=time.clock)
t.start()
time.sleep(5)
elapsed = t.stop()
print('Elapsed time:',elapsed)
FAQs
Time parts of your code easily.
We found that ttictoc 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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.