I know the title is a little bit confusing.
So let me take this code as example:
import timeit
def test1(x,y):
return x*y
def time_cost(func):
start = timeit.default_timer()
func()
stop = timeit.default_timer()
print(stop - start)
time_cost(test1)
I want to give test1's two parameter, x and y, to time_cost function.
But I don't know how to do so.
I have tried this before:
import timeit
def test1(x,y):
return x*y
def time_cost(func):
start = timeit.default_timer()
func
stop = timeit.default_timer()
print(stop - start)
time_cost(test1(1,2))
It can run but the result is so weird that I believe this is wrong.
So how to do this? Thank you all.
xandyas arguments totime_costif it only accepts one agrument (func). If you wanttime_costto accept other arguments, then you need to rewrite it so it accepts those other arguments.