Created
December 5, 2020 10:48
-
-
Save romanitalian/08ef797438f7746bfc618e587a722e32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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