I have a class that contains a methodT to be used by another class methodM, and I want to time the run time of methodT.
Here are the things I've tried
Class MyClass(threading.Thread):
def __init__():
threading.Thread.__init__(self)
def run_porcess(self, args)
# start a subprocess and print output
def run(self):
# ==========================================
# method A:
# ==========================================
start_time = time.clock()
self.run_process('args')
elapsed = time.clock() - start_time
print(elapsed)
#===========================================
# method B:
#===========================================
timeit.timeit('self.run_process("args")')
With method A, I can get an result, but I believe it is a less accurate one compared to one that timeit gives.
However, with method B, timeit will produce an NameError as it doesn't recognize self.run_process
I've read the this post, and tried adding the timewrapper method
def timewrapper(args)
return self.run_process(args)
it just doesn't work for me as it gives a NameError: global name 'timewrapper' is not defined
.
My question is how do I correctly implement the method B using timeit?
NOTE: I cannot use modules other than core python