File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
pyperformance/data-files/benchmarks/bm_decimal_factorial Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 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:
2021 import _decimal
2122except ImportError :
2223 _decimal = None
23-
24+ import sys
2425
2526import 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 )
3954def bench_decimal_factorial ():
4055 c = decimal .getcontext ()
4156 if _decimal :
You can’t perform that action at this time.
0 commit comments