Author vstinner
Recipients belopolsky, benhoyt, benjamin.peterson, ethan.furman, fdrake, lemburg, mrabarnett, serhiy.storchaka, vstinner
Date 2017-10-18.08:45:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1508316341.22.0.213398074469.issue31803@psf.upfronthosting.co.za>
In-reply-to
Content
(I reopen the issue since the discussion is not over.)

Marc-Andre Lemburg: "time.cock() is used in a lot of code."

I ran a quick search on GitHub. I found different use cases of time.clock():

1) Measure performance. On Windows, time.clock() has a very good precision, *much* better than any other clock. For example, time.process_time() has a resolution of 15.6 ms whereas time.clock() has a resolution of 100 ns (or 0.0001 ms):
https://www.python.org/dev/peps/pep-0564/#windows


2) An explicit check that time.clock() doesn't include sleep. I guess that people are using such snippet to explain this behaviour?

https://github.com/pbarton666/PES_Python_examples_and_solutions/blob/master/py_time.py

---

#py_time.py

import time
print(time.clock(), time.time())
time.sleep(1)  #seconds
print(time.clock(), time.time())
---


Ethan: "I agree with MAL; removing functions just makes multi-version code more painful."

We have two choices:

* Deprecate and then remove time.clock(): break the backward compatibility -- currently chosen solution
* Modify time.clock() to get a portable behaviour: break the backward compatibility

Depending which clock we choose for time.clock(), we may break more and less code, I would vote for using the time.perf_counter() clock in time.clock(). It means no change on Windows, but modify the behaviour on Unix if the code sleeps (time.sleep or I/O).

It seems like time.clock() is mostly used for benchmarking, and time.perf_counter() is documented as the best clock for such use case. In the benchmarks I saw on GitHub, the benchmarked code didn't sleep, it was more likely pure CPU-bound.


Marc-Andre, Ethan: What do you think of removing the deprecation warning from the C (my last commit), leave the deprecation warning in the documentation, and modify time.clock() to become an alias to time.perf_counter()?

By alias, I really mean time.clock = time.perf_counter, so time.clock.__name__ would say "perf_counter".
History
Date User Action Args
2017-10-18 08:45:41vstinnersetrecipients: + vstinner, lemburg, fdrake, belopolsky, benjamin.peterson, mrabarnett, benhoyt, ethan.furman, serhiy.storchaka
2017-10-18 08:45:41vstinnersetmessageid: <1508316341.22.0.213398074469.issue31803@psf.upfronthosting.co.za>
2017-10-18 08:45:41vstinnerlinkissue31803 messages
2017-10-18 08:45:40vstinnercreate