I have the following situation : I want to time a method for multiple objects :
class Foo():
  def method(self):
    pass
class Bar():
  def method(self, x):
    print(x)
More specifically, I want to have a list that gets appended with the execution time every time the method is called.
So basically, I want to have a function time_method such that the following code will print the time of 3 executions of the method method for the x object.
x = Foo()
y = time_method(x, 'method')
for i in range(3):
  y.method()
print(y.get_time())
So basically y would need to act exactly like x everywhere except when y.method() is called in which case it would also record the time of execution. The list of time of execution could then be accessed by the get_time method specific to y. This time_method function should work on any object.
 
    