Bench decorator

decbench.bench(func)[source]

Decorator to time a function.

Parameters:
  • f (function) – The function to benchmark.
  • args (list) – List of arguments for the function f.
  • kwargs (dict) – Dictionnary of positional arguments for f.
Returns:

real time to execute f and result of f

Return type:

tuple

Example:

>>> from time import sleep
>>> @bench
... def super_func(numbers):
...     sleep(1)
...     return numbers
>>> bench_time, func_res = super_func([3, 4, 5])
>>> 1. < bench_time < 1.1
True
>>> func_res
[3, 4, 5]