A very simple decorator to notify users (no profiling) about the execution time of some parts of your code.

import time
 
def timemeth(func):
    "Internal class method timing decorator"
    def _inner(self, *args, **kw):
        start = time.time()
        res = func(self, *args, **kw)
        self.timed = time.time() - start
        return res
    return _inner
 
class TimedClass:
    def __init__(self):
        self.timed = 0
 
class Sample(TimedClass):
    @timemeth
    def learn(self):
        for i in range(1000000):
            i * i
 
if __name__ == "__main__": 
    s = Sample()
    print "Learning sample..."
    s.learn()
    print "Learning done ! (%.2f secs)" % s.timed

outputs:

$ python timedclass.py
Learning sample...
Learning done ! (2.01 secs)