Measuring the time it takes for a function to run and complete in Python

后端 未结 3 1395
悲哀的现实
悲哀的现实 2021-01-13 03:01

In Python 3.4.1, I\'m trying to measure how long it takes for a function to run and complete then recording it. I\'m currently doing it this like so:

startti         


        
3条回答
  •  耶瑟儿~
    2021-01-13 03:47

    For quick performance analyses I use the following two lines (plus imports):

    import time
    import numpy as np
    
    t = time.time()
    # ...
    print np.round_(time.time() - t, 3), 'sec elapsed'
    

    It's short, simple and all I usually need.

    (In most cases I've imported numpy anyway. So thats no overhead for me.)

提交回复
热议问题