10000 Expose the clock info · python/cpython@bed30c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit bed30c3

Browse files
committed
Expose the clock info
1 parent 22a94a7 commit bed30c3

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Lib/test/support/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2370,21 +2370,26 @@ class CPUStopwatch:
23702370
23712371
N.B.:
23722372
- This *includes* time spent in other threads.
2373-
- Some systems only have a coarse 1/64 second resolution.
2373+
- Some systems only have a coarse resolution; check
2374+
stopwatch.clock_info.rseolution if.
23742375
23752376
Usage:
23762377
23772378
with ProcessStopwatch() as stopwatch:
23782379
...
23792380
elapsed = stopwatch.seconds
2381+
resolution = stopwatch.clock_info.resolution
23802382
"""
23812383
def __enter__(self):
23822384
get_time = time.process_time
2385+
clock_info = time.get_clock_info('process_time')
23832386
if get_time() <= 0: # some platforms like WASM lack process_time()
23842387
get_time = time.monotonic
2388+
clock_info = time.get_clock_info('monotonic')
23852389
self.context = disable_gc()
23862390
self.context.__enter__()
23872391
self.get_time = get_time
2392+
self.clock_info = clock_info
23882393
self.start_time = get_time()
23892394
return self
23902395

Lib/test/test_int.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ def test_denial_of_service_prevented_int_to_str(self):
675675
# Ensuring that we chose a slow enough conversion to measure.
676676
# It takes 0.1 seconds on a Zen based cloud VM in an opt build.
677677
# Some OSes have a low res 1/64s timer, skip if hard to measure.
678-
if sw_convert.seconds < 1/64:
678+
if sw_convert.seconds < sw_convert.clock_info.resolution * 2:
679679
raise unittest.SkipTest('"slow" conversion took only '
680680
f'{sw_convert.seconds} seconds.')
681681

@@ -714,7 +714,7 @@ def test_denial_of_service_prevented_str_to_int(self):
714714
# Ensuring that we chose a slow enough conversion to measure.
715715
# It takes 0.1 seconds on a Zen based cloud VM in an opt build.
716716
# Some OSes have a low res 1/64s timer, skip if hard to measure.
717-
if sw_convert.seconds < 1/64:
717+
if sw_convert.seconds < sw_convert.clock_info.resolution * 2:
718718
raise unittest.SkipTest('"slow" conversion took only '
719719
f'{sw_convert.seconds} seconds.')
720720

0 commit comments

Comments
 (0)
0