sloth.simple
: Simple timing functions¶
sloth.simple
is a module providing helpful functions that are generally simpler to use than the classes
they wrap in the main API.
-
sloth.simple.
call_after
(seconds, func, args=None, kwargs=None)¶ Call func after seconds have elapsed.
- Parameters
seconds (int) – The number of seconds to call func after.
func (function) – The function to call after seconds seconds have elapsed.
args (list or tuple or None) – Positional arguments to pass to func.
kwargs (dict or None) – Keyword arguments to pass to func.
- Raises
TypeError – if any of the arguments have incorrect types
-
sloth.simple.
time_callable
(callable, n, *args, **kwargs)¶ Time how long it takes to execute _callable, run iterations times and averaged.
- Parameters
func (function) – The callable object to time
n (int) – Number of times to run and average _callable
args – Positional arguments to be passed directly to _callable
kwargs – Keyword arguments to be passed directly to _callable
- Returns
how long it took for the callable to run, averaged
- Return type
float
- Raises
TypeError – if any of the arguments have incorrect types
-
sloth.simple.
time_eval
(snippet, n, gbls=None, lcls=None)¶ Speedtest
eval(statement, gbls, lcls)
. See the eval docs docs for more info.- Parameters
snippet (str or bytes or code) – The code statement to evaluate.
n (int) – Number of times to run and average the code.
- Returns
How long the evaluation took to run
- Return type
float
-
sloth.simple.
time_exec
(snippet, n, gbls=None, lcls=None)¶ Speedtest
exec(statement, gbls, lcls)
. See the exec docs docs for more info.- Parameters
snippet (str or bytes or code) – The code statement to execute.
n (int) – Number of times to run and average the code.
- Returns
How long the execute took to run
- Return type
float