Skip to content

v1.0 Just a Python program for prime calculation

Latest

Choose a tag to compare

@kreier kreier released this 09 May 13:36
· 31 commits to main since this release
dec32ce

This is only here to have a release at all, since many benchmarks are combined here. It's just the oldest one I use myself, even though I started with Basic and a far worse algorithm. See here

The code is simple:

import math, time
last = 1000000
found = 4             # we start from 11, know 2, 3, 5, 7
print(f"Prime numbers to {last}")
start = time.monotonic()
for number in range(11, last, 2):
    prime = True
    for divider in range(3, int(math.sqrt(number))+1, 2):
        if number % divider == 0:
            prime = False
            break
    if prime:
        found += 1
end = time.monotonic()
print(f"This took: {(end - start)} seconds.")
print(f"I found {found} prime numbers.")