diff --git a/pyperformance/data-files/benchmarks/MANIFEST b/pyperformance/data-files/benchmarks/MANIFEST index 1af2a6a0..6d25e408 100644 --- a/pyperformance/data-files/benchmarks/MANIFEST +++ b/pyperformance/data-files/benchmarks/MANIFEST @@ -39,6 +39,8 @@ chaos comprehensions crypto_pyaes dask +decimal_factorial +decimal_pi deepcopy deltablue django_template diff --git a/pyperformance/data-files/benchmarks/bm_decimal_factorial/pyproject.toml b/pyperformance/data-files/benchmarks/bm_decimal_factorial/pyproject.toml index a6ece1c5..a6db82f3 100644 --- a/pyperformance/data-files/benchmarks/bm_decimal_factorial/pyproject.toml +++ b/pyperformance/data-files/benchmarks/bm_decimal_factorial/pyproject.toml @@ -8,3 +8,5 @@ dynamic = ["version"] [tool.pyperformance] name = "decimal_factorial" tags = "decimal" +# Until fix for python/cpython#140036 will be backported. +unsupported_implementations = ["pypy"] diff --git a/pyperformance/data-files/benchmarks/bm_decimal_factorial/run_benchmark.py b/pyperformance/data-files/benchmarks/bm_decimal_factorial/run_benchmark.py index dceba16b..a5cd12ad 100644 --- a/pyperformance/data-files/benchmarks/bm_decimal_factorial/run_benchmark.py +++ b/pyperformance/data-files/benchmarks/bm_decimal_factorial/run_benchmark.py @@ -4,6 +4,8 @@ - 2024-06-14: Michael Droettboom copied this from Modules/_decimal/tests/bench.py in the CPython source and adapted to use pyperf. +- 2026-09-26: Sergey B Kirpichev copied + increase_int_max_str_digits() decorator. """ # Original copyright notice in CPython source: @@ -15,6 +17,8 @@ import decimal +import sys +from functools import wraps import pyperf @@ -31,6 +35,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() c.prec = decimal.MAX_PREC @@ -38,7 +56,6 @@ def bench_decimal_factorial(): c.Emin = decimal.MIN_EMIN for n in [10000, 100000]: - # C version of decimal _ = factorial(decimal.Decimal(n), 0)