Files
Mastering-Python-2e-code_2/CH_12_performance/T_08_line_profiler.py
T
2022-05-05 18:25:55 +02:00

26 lines
428 B
Python

import itertools
@profile
def primes():
n = 2
primes = set()
while True:
for p in primes:
if n % p == 0:
break
else:
primes.add(n)
yield n
n += 1
if __name__ == '__main__':
total = 0
n = 2000
for prime in itertools.islice(primes(), n):
total += prime
print('The sum of the first %d primes is %d' % (n, total))