I'm new to Python and trying to plot the computational speeds of two functions. For example, having defining two functions (see below), how can I return the time for each iteration using the timeit function in IPython/Jupyter?
def func1(x) :
return x*x
def func2(x) :
return x+x
%timeit for x in range(100) : func1(x)
%timeit for x in range(100) : func2(x)
I read https://ipython.org/ipython-doc/3/interactive/magics.html that I can use '-o' to "return a TimeitResult that can be stored in a variable to inspect the result in more details."
But how do I save it to a variable say 'func1_time' and how can I read the time for each iteration? My goal is to plot x vs time for both functions.
Any help will be much appreciated. Thanks.