How do I get monotonic time durations in python?

前端 未结 5 871
感情败类
感情败类 2020-11-27 03:09

I want to log how long something takes in real walltime. Currently I\'m doing this:

startTime = time.time()
someSQLOrSomething()
print \"That took %.3f secon         


        
5条回答
  •  [愿得一人]
    2020-11-27 03:59

    time.monotonic() might be useful:

    Return the value (in fractional seconds) of a monotonic clock, i.e. a clock that cannot go backwards. The clock is not affected by system clock updates. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid.

提交回复
热议问题