MCPcopy Index your code
hub / github.com/python/cpython / measure_itimer_resolution

Method measure_itimer_resolution

Lib/test/test_signal.py:1230–1252  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1228 self.addCleanup(signal.signal, signum, old_handler)
1229
1230 def measure_itimer_resolution(self):
1231 N = 20
1232 times = []
1233
1234 def handler(signum=None, frame=None):
1235 if len(times) < N:
1236 times.append(time.perf_counter())
1237 # 1 µs is the smallest possible timer interval,
1238 # we want to measure what the concrete duration
1239 # will be on this platform
1240 signal.setitimer(signal.ITIMER_REAL, 1e-6)
1241
1242 self.addCleanup(signal.setitimer, signal.ITIMER_REAL, 0)
1243 self.setsig(signal.SIGALRM, handler)
1244 handler()
1245 while len(times) < N:
1246 time.sleep(1e-3)
1247
1248 durations = [times[i+1] - times[i] for i in range(len(times) - 1)]
1249 med = statistics.median(durations)
1250 if support.verbose:
1251 print("detected median itimer() resolution: %.6f s." % (med,))
1252 return med
1253
1254 def decide_itimer_count(self):
1255 # Some systems have poor setitimer() resolution (for example

Callers 1

decide_itimer_countMethod · 0.95

Calls 5

setsigMethod · 0.95
handlerFunction · 0.85
addCleanupMethod · 0.80
medianMethod · 0.80
sleepMethod · 0.45

Tested by

no test coverage detected