Файли
openidea/fixtures/python-profiling/cpu_heavy.py
T
LU XIANGRUIтаwildcatDownstairs 93368d4379 feat(profiler): profile Python runs with cProfile (#6512)
Profile on a Python configuration runs it under cProfile from the standard library when py-spy can't sample without root (always on macOS), or when Settings > Python > Profiler chooses cProfile. Scripts, modules and pytest configurations run with their own interpreter; stopping the run still writes the snapshot, which opens in the profiler view.

Co-authored-by: wildcatDownstairs <[email protected]>
2026-11-28 00:54:42 +08:00

37 рядки
731 B
Python
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
"""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)
while "--loop" in sys.argv:
fib(18)
if __name__ == "__main__":
main()