Skip to content

Commit 8aee4dc

Browse files
Enable the decimal_{pi,factorial} benchmarks (#491)
Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent e08cfff commit 8aee4dc

5 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎doc/benchmarks.rst‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,26 @@ See `pyaes <https://github.com/ricmoo/pyaes>`_: A pure-Python implementation of
169169
the AES block cipher algorithm and the common modes of operation (CBC, CFB,
170170
CTR, ECB and OFB).
171171

172+
decimal_factorial
173+
-----------------
174+
175+
Compute ``10000!`` and ``100000!`` exactly with the ``decimal`` module, using
176+
binary splitting.
177+
178+
This benchmark is skipped on PyPy, where the pure-Python ``decimal`` module
179+
hangs at this precision (see `pypy/pypy#5814
180+
<https://github.com/pypy/pypy/issues/5814>`_).
181+
182+
decimal_pi
183+
----------
184+
185+
Compute ``pi`` with the ``decimal`` module at context precisions of 9 and 19
186+
digits.
187+
188+
This measures the speed of many operations on small ``Decimal`` values.
189+
See also the ``pidigits`` benchmark, which does a similar computation
190+
with ``int``.
191+
172192
deepcopy
173193
--------
174194

‎doc/changelog.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Version 2.0.0 (unreleased)
1919
and its results are mostly noise
2020
* Fix benchmark selection checking Python version requirements against the
2121
running interpreter instead of the target specified by ``--python``
22+
* Enable the ``decimal_factorial`` and ``decimal_pi`` benchmarks, which were
23+
added in 1.12.0 but never listed in the manifest. ``decimal_factorial`` is
24+
skipped on PyPy.
2225

2326
Version 1.14.0 (2026-02-07)
2427
---------------------------

‎pyperformance/data-files/benchmarks/MANIFEST‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ chaos <local>
3939
comprehensions <local>
4040
crypto_pyaes <local>
4141
dask <local>
42+
decimal_factorial <local>
43+
decimal_pi <local>
4244
deepcopy <local>
4345
deltablue <local>
4446
django_template <local>

‎pyperformance/data-files/benchmarks/bm_decimal_factorial/pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ dynamic = ["version"]
88
[tool.pyperformance]
99
name = "decimal_factorial"
1010
tags = "decimal"
11+
unsupported_implementations = ["pypy"] # pypy/pypy#5814

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- 2024-06-14: Michael Droettboom copied this from
55
Modules/_decimal/tests/bench.py in the CPython source and adapted to use
66
pyperf.
7+
- 2026-12-01: Sergey B Kirpichev, use sys.set_int_max_str_digits(0).
78
"""
89

910
# Original copyright notice in CPython source:
@@ -15,6 +16,7 @@
1516

1617

1718
import decimal
19+
import sys
1820

1921

2022
import pyperf
@@ -38,11 +40,12 @@ def bench_decimal_factorial():
3840
c.Emin = decimal.MIN_EMIN
3941

4042
for n in [10000, 100000]:
41-
# C version of decimal
4243
_ = factorial(decimal.Decimal(n), 0)
4344

4445

4546
if __name__ == "__main__":
47+
sys.set_int_max_str_digits(0)
48+
4649
runner = pyperf.Runner()
4750
runner.metadata["description"] = "decimal_factorial benchmark"
4851

0 commit comments

Comments
 (0)