Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
+ increase_int_max_str_digits() decorator
  • Loading branch information
skirpichev committed Feb 22, 2026
commit b1847bb4dfaa4c429394bd56663f88b03141c19f
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
Modules/_decimal/tests/bench.py in the CPython source and adapted to use
pyperf.
- 2026-02-22: Sergey B Kirpichev adapted context settings and tested
values to support also pure-Python decimal module.
values to support also pure-Python decimal module, copy
increase_int_max_str_digits() decorator.
"""

# Original copyright notice in CPython source:
Expand All @@ -20,7 +21,7 @@
import _decimal
except ImportError:
_decimal = None

import sys

import pyperf

Expand All @@ -36,6 +37,20 @@ def factorial(n, m):
return factorial(n, (n + m) // 2) * factorial((n + m) // 2 + 1, m)


def increase_int_max_str_digits(maxdigits):
def _increase_int_max_str_digits(func, maxdigits=maxdigits):
@wraps(func)
def wrapper(*args, **kwargs):
previous_int_limit = sys.get_int_max_str_digits()
sys.set_int_max_str_digits(maxdigits)
ans = func(*args, **kwargs)
sys.set_int_max_str_digits(previous_int_limit)
return ans
return wrapper
return _increase_int_max_str_digits


@increase_int_max_str_digits(maxdigits=10000000)
def bench_decimal_factorial():
c = decimal.getcontext()
if _decimal:
Expand Down
Loading