docstr: Regression test: ensure we fail before performing O(N**2) work.
code: def test_denial_of_service_prevented_str_to_int(self):
      """Regression test: ensure we fail before performing O(N**2) work."""
      maxdigits = sys.get_int_max_str_digits()
      assert maxdigits < 100_000, maxdigits  # A test prerequisite.
      get_time = time.process_time
      if (
          get_time() <= 0
      ):  # some platforms like WASM lack process_time()
          get_time = time.monotonic
  
      digits = 133700
      huge = "8" * digits
      with support.adjust_int_max_str_digits(digits):
          start = get_time()
          int(huge)
      seconds_to_convert = get_time() - start
      # 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.
      # Some OSes have a low res 1/64s timer, skip if hard to measure.
      if seconds_to_convert < 1 / 64:
          raise unittest.SkipTest(
              '"slow" conversion took only '
              f"{seconds_to_convert} seconds."
          )
  
      with support.adjust_int_max_str_digits(digits - 1):
          with self.assertRaises(ValueError) as err:
              start = get_time()
              int(huge)
          seconds_to_fail_huge = get_time() - start
      self.assertIn("conversion", str(err.exception))
      self.assertLessEqual(seconds_to_fail_huge, seconds_to_convert / 2)
  
      # Now we test that a conversion that would take 30x as long also fails
      # in a similarly fast fashion.
      extra_huge = "7" * 1_200_000
      with self.assertRaises(ValueError) as err:
          start = get_time()
          # If not limited, 8 seconds in the Zen based cloud VM.
          int(extra_huge)
      seconds_to_fail_extra_huge = get_time() - start
      self.assertIn("conversion", str(err.exception))
      self.assertLessEqual(
          seconds_to_fail_extra_huge, seconds_to_convert / 2
      )
  
imports: import sys
  import time
  import unittest
  from unittest import mock
  from test import support
  from test.test_grammar import VALID_UNDERSCORE_LITERALS, INVALID_UNDERSCORE_LITERALS
label_desc: Use image node_id 8 for calling the IntStrDigitLimitsTests obj's underlying member method code with example usage: obj.test_denial_of_service_prevented_str_to_int() without return types