🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

noiftimer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

noiftimer

Timing class for measuring elapsed time and average elapsed time.

2.5.0
Maintainers
1

noiftimer

Simple timer class to track elapsed time.
Install with:

pip install noiftimer

Usage:

from noiftimer import Timer, time_it, log_time
import time

Timer object:

>>> def very_complicated_function():
...     time.sleep(1)
...
>>> timer = Timer()
>>> for _ in range(10):
...     timer.start()
...     very_complicated_function()
...     timer.stop()
...
>>> print(timer.stats)
elapsed time: 1s 1ms 173us
average elapsed time: 1s 912us
>>> timer.elapsed
1.001173496246338
>>> timer.elapsed_str
'1s 1ms 173us'
>>> timer.average_elapsed
1.0009121656417848
>>> timer.average_elapsed_str
'1s 912us'

time_it decorator (executes the decorated function 10 times)

>>> @time_it(10)
... def very_complicated_function():
...     time.sleep(1)
...
>>> very_complicated_function()
very_complicated_function average execution time: 1s 469us

Alternatively, the log_time decorator can be used to instead log the execution time to a file.

Keywords

FAQs

Did you know?

Socket

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.

Install

Related posts