mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
Add dependency-free CPU-bound workloads adapted from pyperformance 1.14.0 to cover interpreter, standard-library serialization, regex, numeric, and garbage-collection paths under the existing Criterion and CodSpeed harnesses. Keep inputs deterministic and scale expensive cases for simulation while checking that benchmark execution does not leak interpreter state. Assisted-by: Codex:gpt-5.6-sol
58 lines
1.1 KiB
Python
58 lines
1.1 KiB
Python
# Adapted from python/pyperformance 1.14.0 (pidigits).
|
|
# coding: utf-8
|
|
"""
|
|
Calculating some of the digits of π.
|
|
|
|
This benchmark stresses big integer arithmetic.
|
|
|
|
Adapted from code on:
|
|
http://benchmarksgame.alioth.debian.org/
|
|
"""
|
|
|
|
import itertools
|
|
|
|
DEFAULT_DIGITS = 2000
|
|
icount = itertools.count
|
|
islice = itertools.islice
|
|
|
|
|
|
def gen_x():
|
|
return map(lambda k: (k, 4 * k + 2, 0, 2 * k + 1), icount(1))
|
|
|
|
|
|
def compose(a, b):
|
|
aq, ar, as_, at = a
|
|
bq, br, bs, bt = b
|
|
return (aq * bq,
|
|
aq * br + ar * bt,
|
|
as_ * bq + at * bs,
|
|
as_ * br + at * bt)
|
|
|
|
|
|
def extract(z, j):
|
|
q, r, s, t = z
|
|
return (q * j + r) // (s * j + t)
|
|
|
|
|
|
def gen_pi_digits():
|
|
z = (1, 0, 0, 1)
|
|
x = gen_x()
|
|
while 1:
|
|
y = extract(z, 3)
|
|
while y != extract(z, 4):
|
|
z = compose(z, next(x))
|
|
y = extract(z, 3)
|
|
z = compose((10, -10 * y, 0, 1), z)
|
|
yield y
|
|
|
|
|
|
def calc_ndigits(n):
|
|
return list(islice(gen_pi_digits(), n))
|
|
|
|
|
|
def add_cmdline_args(cmd, args):
|
|
cmd.extend(("--digits", str(args.digits)))
|
|
|
|
digits = calc_ndigits(1000)
|
|
assert digits[:10] == [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]
|