I made the timer function for measuring performance of functions
but I got a problem when I use **kwargs for function's parameter
for example when I want to use scipy.stats.zscore(a, axis=0, ddof=0, nan_policy='propagate') only using 3 parameters.
generally I will use like a below code
import scipy.stats as st
temp = np.array([[3,4,2],[2,2,4]])
st.zscore(a=temp, axis=1, nan_policy='omit')
but when I measure performance of scipy.stats.zscore(a, axis=0, ddof=0, nan_policy='propagate') by my function timer, it makes error....
this is my code
import numpy as np
import scipy.stats as st
from time import perf_counter
def timer(f,*args,**kwargs):
start = perf_counter()
if args:
f(*args)
elif kwargs!=None:
f(**kwargs)
return 1000 * (perf_counter() - start)
temp = np.array([[3,4,2],[2,2,4]])
# it has error...
# I know para =["a"=1] is wrong code...
para = ["a" = temp, "axis" = 1, "nan_policy" = "omit"]
used_time = 1000 * np.mean([timer(st.zscore, *para) for _ in range(1000)])
# but *args works very well...
used_time = 1000 * np.mean([timer(st.zscore, temp) for _ in range(1000)])
so my object is
I want to use **kwargs for timer's callback function's parameter
plz help me..