File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -2370,21 +2370,26 @@ class CPUStopwatch:
2370
2370
2371
2371
N.B.:
2372
2372
- 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.
2374
2375
2375
2376
Usage:
2376
2377
2377
2378
with ProcessStopwatch() as stopwatch:
2378
2379
...
2379
2380
elapsed = stopwatch.seconds
2381
+ resolution = stopwatch.clock_info.resolution
2380
2382
"""
2381
2383
def __enter__ (self ):
2382
2384
get_time = time .process_time
2385
+ clock_info = time .get_clock_info ('process_time' )
2383
2386
if get_time () <= 0 : # some platforms like WASM lack process_time()
2384
2387
get_time = time .monotonic
2388
+ clock_info = time .get_clock_info ('monotonic' )
2385
2389
self .context = disable_gc ()
2386
2390
self .context .__enter__ ()
2387
2391
self .get_time = get_time
2392
+ self .clock_info = clock_info
2388
2393
self .start_time = get_time ()
2389
2394
return self
2390
2395
Original file line number Diff line number Diff line change @@ -675,7 +675,7 @@ def test_denial_of_service_prevented_int_to_str(self):
675
675
# Ensuring that we chose a slow enough conversion to measure.
676
676
# It takes 0.1 seconds on a Zen based cloud VM in an opt build.
677
677
# 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 :
679
679
raise unittest .SkipTest ('"slow" conversion took only '
680
680
f'{ sw_convert .seconds } seconds.')
681
681
@@ -714,7 +714,7 @@ def test_denial_of_service_prevented_str_to_int(self):
714
714
# Ensuring that we chose a slow enough conversion to measure.
715
715
# It takes 0.1 seconds on a Zen based cloud VM in an opt build.
716
716
# 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 :
718
718
raise unittest .SkipTest ('"slow" conversion took only '
719
719
f'{ sw_convert .seconds } seconds.' )
720
720
You can’t perform that action at this time.
0 commit comments