How do you determine a processing time in Python?

前端 未结 9 1515
天涯浪人
天涯浪人 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:08

    If all you want is the time between two points in code (and it seems that's what you want) I have written tic() toc() functions ala Matlab's implementation. The basic use case is:

    tic()
    
    ''' some code that runs for an interesting amount of time '''
    
    toc()
    
    # OUTPUT:
    # Elapsed time is: 32.42123 seconds
    

    Super, incredibly easy to use, a sort of fire-and-forget kind of code. It's available on Github's Gist https://gist.github.com/tyleha/5174230

提交回复
热议问题