Skip to content

Instantly share code, notes, and snippets.

@romanitalian
Created December 5, 2020 10:48
Show Gist options
  • Save romanitalian/08ef797438f7746bfc618e587a722e32 to your computer and use it in GitHub Desktop.
Save romanitalian/08ef797438f7746bfc618e587a722e32 to your computer and use it in GitHub Desktop.
import math
from time import perf_counter
from numba import njit
@njit(fastmath=True)
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
@njit(fastmath=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