/usr/lib/python3/dist-packages/pytest_benchmark/timers.py is in python3-pytest-benchmark 3.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | from time import time as timeout_timer
try:
from __pypy__.time import clock_gettime
from __pypy__.time import CLOCK_MONOTONIC
def monotonic():
return clock_gettime(CLOCK_MONOTONIC)
except ImportError:
from timeit import default_timer
else:
default_timer = monotonic
from .compat import XRANGE
def compute_timer_precision(timer):
precision = None
points = 0
timeout = timeout_timer() + 1.0
previous = timer()
while timeout_timer() < timeout or points < 5:
for _ in XRANGE(10):
t1 = timer()
t2 = timer()
dt = t2 - t1
if 0 < dt:
break
else:
dt = t2 - previous
if dt <= 0.0:
continue
if precision is not None:
precision = min(precision, dt)
else:
precision = dt
points += 1
previous = timer()
return precision
|