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)