Skip to content

Commit b1847bb

Browse files
committed
+ increase_int_max_str_digits() decorator
1 parent 243a809 commit b1847bb

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

pyperformance/data-files/benchmarks/bm_decimal_factorial/run_benchmark.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
Modules/_decimal/tests/bench.py in the CPython source and adapted to use
66
pyperf.
77
- 2026-02-22: Sergey B Kirpichev adapted context settings and tested
8-
values to support also pure-Python decimal module.
8+
values to support also pure-Python decimal module, copy
9+
increase_int_max_str_digits() decorator.
910
"""
1011

1112
# Original copyright notice in CPython source:
@@ -20,7 +21,7 @@
2021
import _decimal
2122
except ImportError:
2223
_decimal = None
23-
24+
import sys
2425

2526
import pyperf
2627

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

3839

40+
def increase_int_max_str_digits(maxdigits):
41+
def _increase_int_max_str_digits(func, maxdigits=maxdigits):
42+
@wraps(func)
43+
def wrapper(*args, **kwargs):
44+
previous_int_limit = sys.get_int_max_str_digits()
45+
sys.set_int_max_str_digits(maxdigits)
46+
ans = func(*args, **kwargs)
47+
sys.set_int_max_str_digits(previous_int_limit)
48+
return ans
49+
return wrapper
50+
return _increase_int_max_str_digits
51+
52+
53+
@increase_int_max_str_digits(maxdigits=10000000)
3954
def bench_decimal_factorial():
4055
c = decimal.getcontext()
4156
if _decimal:

0 commit comments

Comments
 (0)