diff --git a/scripts/cpu-perf-check b/scripts/cpu-perf-check index fee9bd02..35622e92 100755 --- a/scripts/cpu-perf-check +++ b/scripts/cpu-perf-check @@ -77,9 +77,13 @@ def _pkg_max_mhz() -> int: def _burn(stop: float) -> None: + # fixed-width (64-bit-masked) arithmetic keeps this a steady + # ALU load; an unmasked `x` grows ~x**2/iter into a huge bigint, + # degenerating into noisy alloc/mul-bound work (and needless + # memory) across N procs. x: int = 1 while time.perf_counter() < stop: - x += x * x ^ 0x5 + x = (x + (x * x ^ 0x5)) & 0xFFFF_FFFF_FFFF_FFFF def main( diff --git a/tests/conftest.py b/tests/conftest.py index 432b217b..4acf9379 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -171,7 +171,8 @@ def _measure_sustained_headroom( def _read_mhz(path: str) -> int|None: try: - return int(open(path).read()) // 1000 + with open(path) as f: + return int(f.read()) // 1000 except OSError: return None @@ -187,9 +188,13 @@ def _measure_sustained_headroom( return 1. def _burn(stop: float) -> None: + # fixed-width (64-bit-masked) arithmetic keeps this a + # steady ALU load; an unmasked `x` grows ~x**2/iter into + # a huge bigint, degenerating into noisy alloc/mul-bound + # work (and needless memory) across N procs. x: int = 1 while time.perf_counter() < stop: - x += x * x ^ 0x5 + x = (x + (x * x ^ 0x5)) & 0xFFFF_FFFF_FFFF_FFFF # explicit `fork` ctx so we're immune to whatever global # mp start-method tractor/the suite may have set (`spawn`