Reputation: 321
I have to time how long it takes a function to run that returns a list. I want to store the time it takes it to run in a variable, and store the list the function returns. How do I go about storing both?
Example that returns the time but loses the result:
t1 = timeit.timeit(myFunction())
If myFunction returns a list, how do I store it and the time? Is this possible?
Upvotes: 1
Views: 483
Reputation: 36662
You can do it the "old fashion way":
start = time.time()
var = myFunction()
end = time.time()
time_needed = end - start
print(var, time_needed)
Upvotes: 1