дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-28 13:32:29 +02:00
a_stopped_run_still_writes_its_profile sent SIGINT right after the fixture printed done, which could land before the loop ran, so the profile held only the initial fib(22) calls and the 'the loop ran' assertion failed. The fixture now prints looped after its first fib(18), and the test stops the run only after reading it, then checks for both completed passes. Fixes #6585 Co-authored-by: principalwater <[email protected]>
40 рядки
804 B
Python
40 рядки
804 B
Python
"""A small CPU-heavy program to profile (Run › Profile).
|
||
|
||
`fib` is recursive, `primes` calls a generator, and `checksum` spends its time in
|
||
built-ins. With `--loop` it keeps working until it is stopped.
|
||
"""
|
||
|
||
import sys
|
||
|
||
|
||
def fib(n):
|
||
return n if n < 2 else fib(n - 1) + fib(n - 2)
|
||
|
||
|
||
def primes(limit):
|
||
found = []
|
||
for n in range(2, limit):
|
||
if all(n % p for p in found if p * p <= n):
|
||
found.append(n)
|
||
return found
|
||
|
||
|
||
def checksum(words):
|
||
return sum(sorted(hash(w) % 997 for w in words))
|
||
|
||
|
||
def main():
|
||
fib(22)
|
||
primes(20000)
|
||
checksum(str(i) for i in range(200000))
|
||
print("done", flush=True)
|
||
if "--loop" in sys.argv:
|
||
fib(18)
|
||
print("looped", flush=True)
|
||
while True:
|
||
fib(18)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|