Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import time
- def main(time):
- time_temp = []
- for i in range(1, time+1):
- time_temp.append(sieve(2000))
- with open('time.csv','w') as f:
- for i in time_temp:
- f.write(str(i)+'\n')
- f.close()
- def sieve(max):
- start = time.perf_counter()
- a = [True] * (max + 1)
- a[0] = a[1] = False
- for i in range(2, math.floor(math.sqrt(max))):
- if a[i]:
- for j in range(i*i, max+1, i):
- a[j] = False
- prime = []
- for i in range(2, max+1):
- if a[i]:
- prime.append(i)
- end = time.perf_counter()
- time_use = (end - start)*1000
- # change this to change file name
- with open('K_Last.csv','w') as f:
- for i in prime:
- f.write(str(i)+'\n')
- f.close()
- return time_use
- main(100)
Advertisement
Add Comment
Please, Sign In to add comment