[Tutor] Time

Dave Angel davea at ieee.org
Wed Jun 23 03:11:32 CEST 2010


Ahmed AL-Masri wrote:
> Hi, 
> I would calculate the running time of my simulation code.
> any one know how to do that?
>
> example
>
> def demo():
>     ########### the starting point of time should be 0
>      f.simulate(data)
>     ########### the end of the class so need to find the time in Sec.?
>     ########### print time in sec.
> if __name__ == '__main__':
>     demo()
>
> look forward to seeing the answer,
>
> Thanks a lot,
> A. Naufal
>   

If you're really looking to measure performance, you should use the 
timeit module.  But for simply deciding how much time has elapsed 
between two points in your code, you can use the time.time() function.

import time

start = time.time()
...  do some work
end = time.time()-start


DaveA


More information about the Tutor mailing list