[pypy-issue] Issue #1956: clock() has odd timing (pypy/pypy)

Claire Charron issues-reply at bitbucket.org
Thu Jan 8 19:29:59 CET 2015

New issue 1956: clock() has odd timing

Claire Charron:

cross-post from Stack Overflow: https://stackoverflow.com/questions/27829225/why-is-pypys-clock-so-imprecise

See the following code:

from time import clock
from random import randint

times = []
for _ in range(10):
  start = clock()
  sum(i * i for i in range(randint(1000000, 2000000))) # waste time
  end = clock()
  times.append(int((end - start) * 1000000))

for t in times:
  print(t, "µs")

If you run it, you'll notice that clock() is only accurate to about 1/30th of a second. This isn't sufficient for any kind of timing.

More information about the pypy-issue mailing list