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:
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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments