How do you determine a processing time in Python?

前端 未结 9 1559
天涯浪人
天涯浪人 2020-12-09 14:27

I\'m new to Python, and confused by the date/time documentation. I want to compute the time that it takes to perform a computation.

In java, I would write:

9条回答
  •  孤城傲影
    2020-12-09 15:12

    For some further information on how to determine the processing time, and a comparison of a few methods (some mentioned already in the answers of this post) - specifically, the difference between:

    start = time.time()
    

    versus the now obsolete (as of 3.3, time.clock() is deprecated)

    start = time.clock()
    

    see this other article on Stackoverflow here:

    Python - time.clock() vs. time.time() - accuracy?

    If nothing else, this will work good:

    start = time.time()
    
    ... do something
    
    elapsed = (time.time() - start)
    

提交回复
热议问题