GH-114911: use time.perf_counter in Stopwatch (GH-131469)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
Chris Eibl 2025-04-28 13:55:08 +02:00 committed by GitHub
parent e577439803
commit 11f457cf41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 20 deletions

View file

@ -590,7 +590,7 @@ class IntStrDigitLimitsTests(unittest.TestCase):
digits = 78_268
with (
support.adjust_int_max_str_digits(digits),
support.CPUStopwatch() as sw_convert):
support.Stopwatch() as sw_convert):
huge_decimal = str(huge_int)
self.assertEqual(len(huge_decimal), digits)
# Ensuring that we chose a slow enough conversion to measure.
@ -605,7 +605,7 @@ class IntStrDigitLimitsTests(unittest.TestCase):
with support.adjust_int_max_str_digits(int(.995 * digits)):
with (
self.assertRaises(ValueError) as err,
support.CPUStopwatch() as sw_fail_huge):
support.Stopwatch() as sw_fail_huge):
str(huge_int)
self.assertIn('conversion', str(err.exception))
self.assertLessEqual(sw_fail_huge.seconds, sw_convert.seconds/2)
@ -615,7 +615,7 @@ class IntStrDigitLimitsTests(unittest.TestCase):
extra_huge_int = int(f'0x{"c"*500_000}', base=16) # 602060 digits.
with (
self.assertRaises(ValueError) as err,
support.CPUStopwatch() as sw_fail_extra_huge):
support.Stopwatch() as sw_fail_extra_huge):
# If not limited, 8 seconds said Zen based cloud VM.
str(extra_huge_int)
self.assertIn('conversion', str(err.exception))
@ -630,7 +630,7 @@ class IntStrDigitLimitsTests(unittest.TestCase):
huge = '8'*digits
with (
support.adjust_int_max_str_digits(digits),
support.CPUStopwatch() as sw_convert):
support.Stopwatch() as sw_convert):
int(huge)
# Ensuring that we chose a slow enough conversion to measure.
# It takes 0.1 seconds on a Zen based cloud VM in an opt build.
@ -642,7 +642,7 @@ class IntStrDigitLimitsTests(unittest.TestCase):
with support.adjust_int_max_str_digits(digits - 1):
with (
self.assertRaises(ValueError) as err,
support.CPUStopwatch() as sw_fail_huge):
support.Stopwatch() as sw_fail_huge):
int(huge)
self.assertIn('conversion', str(err.exception))
self.assertLessEqual(sw_fail_huge.seconds, sw_convert.seconds/2)
@ -652,7 +652,7 @@ class IntStrDigitLimitsTests(unittest.TestCase):
extra_huge = '7'*1_200_000
with (
self.assertRaises(ValueError) as err,
support.CPUStopwatch() as sw_fail_extra_huge):
support.Stopwatch() as sw_fail_extra_huge):
# If not limited, 8 seconds in the Zen based cloud VM.
int(extra_huge)
self.assertIn('conversion', str(err.exception))