python timeit function return value

Solutions on MaxInterview for python timeit function return value by the best coders in the world

showing results for - "python timeit function return value"
Debora
16 Sep 2019
1import time
2
3# Function with both args and kwargs ====
4def time_fn( fn, *args, **kwargs ):
5    start = time.perf_counter()
6    results = fn( *args, **kwargs )
7    end = time.perf_counter()
8    print(fn.__name__ + ": " + str(end-start) + "s")
9    return results
10
11res = time_fn(function_name, input, output)
12
13# Function with only arguments ====
14def time_fn(fn, *args):
15    start = time.perf_counter()
16    results = fn(*args)
17    end = time.perf_counter()
18    print(fn.__name__ + ": " + str(end - start) + "s")
19    return results
20
21res = time_fn(function_name, input)