mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +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
55 lines
1.2 KiB
Python
55 lines
1.2 KiB
Python
# Adapted from python/pyperformance 1.14.0 (float).
|
|
"""
|
|
Artificial, floating point-heavy benchmark originally used by Factor.
|
|
"""
|
|
from math import sin, cos, sqrt
|
|
|
|
|
|
POINTS = 100000
|
|
|
|
|
|
class Point(object):
|
|
__slots__ = ('x', 'y', 'z')
|
|
|
|
def __init__(self, i):
|
|
self.x = x = sin(i)
|
|
self.y = cos(i) * 3
|
|
self.z = (x * x) / 2
|
|
|
|
def __repr__(self):
|
|
return "<Point: x=%s, y=%s, z=%s>" % (self.x, self.y, self.z)
|
|
|
|
def normalize(self):
|
|
x = self.x
|
|
y = self.y
|
|
z = self.z
|
|
norm = sqrt(x * x + y * y + z * z)
|
|
self.x /= norm
|
|
self.y /= norm
|
|
self.z /= norm
|
|
|
|
def maximize(self, other):
|
|
self.x = self.x if self.x > other.x else other.x
|
|
self.y = self.y if self.y > other.y else other.y
|
|
self.z = self.z if self.z > other.z else other.z
|
|
return self
|
|
|
|
|
|
def maximize(points):
|
|
next = points[0]
|
|
for p in points[1:]:
|
|
next = next.maximize(p)
|
|
return next
|
|
|
|
|
|
def benchmark(n):
|
|
points = [None] * n
|
|
for i in range(n):
|
|
points[i] = Point(i)
|
|
for p in points:
|
|
p.normalize()
|
|
return maximize(points)
|
|
|
|
result = benchmark(10000)
|
|
assert result.x <= 1.0 and result.y <= 1.0 and result.z <= 1.0
|