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

后端 未结 16 1688
忘掉有多难
忘掉有多难 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 08:48

    clock() -> floating point number

    Return the CPU time or real time since the start of the process or since the first call to clock(). This has as much precision as the system records.

    time() -> floating point number

    Return the current time in seconds since the Epoch. Fractions of a second may be present if the system clock provides them.

    Usually time() is more precise, because operating systems do not store the process running time with the precision they store the system time (ie, actual time)

提交回复
热议问题