Skip to content

Instantly share code, notes, and snippets.

@romanitalian
Created December 5, 2020 10:47
Show Gist options
  • Save romanitalian/2f647dbacf96cf4a23ae6711bad9c7b9 to your computer and use it in GitHub Desktop.
Save romanitalian/2f647dbacf96cf4a23ae6711bad9c7b9 to your computer and use it in GitHub Desktop.
import math
from time import perf_counter
def is_prime(num):
if num == 2:
return True
if num == 1 or not num % 2:
return False
for div in range(3, int(math.sqrt(num)) + 1, 2):
if not num % div:
return False
return True
def do(n):
for i in range(n):
is_prime(i)
if __name__ == '__main__':
N = 10_000_000
st = perf_counter()
do(N)
end = perf_counter()
print(end - st)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment