I defined a function here to calculate the time of procedure 'p' takes.
def timeit(p):
a=time.clock()
p
b=time.clock()
print(b-a)
Then I use another function to test it.
d=pd.DataFrame({'x':np.random.randint(1,100,10000)})
d['s']=None
def f1():
for i in range(10000):
if d.iloc[i,0]<60:
d.iloc[i,1]='under'
elif d.iloc[i,0]<80:
d.iloc[i,1]='ok'
else:
d.iloc[i,1]='best'
Use my timeit:
timeit(f1())
5.140552730154013e-07
The result is absolutely wrong. Why? Is there any problem in my grammar? The true time is:
a=time.clock()
f1()
b=time.clock()
b-a
Out[26]: 5.914697663515881