Python's time.clock() vs. time.time() accuracy?

后端 未结 16 1663
忘掉有多难
忘掉有多难 2020-11-22 08:22

Which is better to use for timing in Python? time.clock() or time.time()? Which one provides more accuracy?

for example:

start = time.clock()
... do          


        
16条回答
  •  温柔的废话
    2020-11-22 09:08

    One thing to keep in mind: Changing the system time affects time.time() but not time.clock().

    I needed to control some automatic tests executions. If one step of the test case took more than a given amount of time, that TC was aborted to go on with the next one.

    But sometimes a step needed to change the system time (to check the scheduler module of the application under test), so after setting the system time a few hours in the future, the TC timeout expired and the test case was aborted. I had to switch from time.time() to time.clock() to handle this properly.

提交回复
热议问题