I'm trying to compare the speed of my functions using timeit but saving the results of these and I can't achieve that. Let me show you a toy example, trying to compare diferent matrix multiplication functions:
from timeit import timeit
import numpy as np
def prod_tensorial (A,B) : return np.tensordot(A,B,(-1,0))
def prod_punto (A,B) : return np.dot(A,B)
def prod_sumeinsten (A,B) : return np.einsum('ij,jk->ik',A,B)
A = np.random.rand(1000,2000)
B = np.random.rand(2000,3000)
fs = ( prod_tensorial, prod_punto, prod_sumeinsten )
ts = [ ]
ps = [ ]
for f in fs:
ts += [ timeit('ps += [f(A,B)]',number=1) ] # error: ps & f didn't recognized
#ts += [ timeit(lambda: f(A,B),number=1) ] # it works but lossing results
print( ts[-1] )
print(np.allclose(*ps))
How you can see, I can't save the results. Do you know how could I do that?