Which is more accurate, time.clock() or time.time()?

Asked 2 years ago, Updated 2 years ago, 90 views

Which is more accurate to use, time.clock() or time.time() when time is measured in python?

For example,

#1. time.clock()
start = time.clock()
#Something code
elapsed = (time.clock() - start)

#2. time.time()
start = time.time()
#Something code
elapsed = (time.time() - start)

Which is the better way out of these two?

What is the difference between printing in python 2.7 and printing in Python?

python time accuracy

2022-09-22 14:09

1 Answers

Officially, starting from Python 3.3, instead of time.clock() time.process_time() or time.It is recommended that you write perf_counter().

In the time module documentation in 2.7:

time.clock() :

Unix returns the time of the current processor to floating point in seconds. "Processor time" and precision are the same as those in C.

Windows returns wall-clock to floating point in seconds how long has passed since the first call was made. The returned value is based on Wind32's QueryPerformanceCounter().


2022-09-22 14:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.