Skip to content

Commit

Permalink
new results from ESP32-C3-DevKitM-1 with C3N4
Browse files Browse the repository at this point in the history
  • Loading branch information
kreier committed Dec 20, 2023
1 parent b035ae7 commit 6ae10cd
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 10 deletions.
2 changes: 1 addition & 1 deletion circuitpython/v5.2_esp32c3/10000000.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
espressif_esp32c3_devkitm_1_n4
Primes to 10000000 took 1840.33 seconds. 0h 30min 40s
Primes to 10000000 took 1656.41 seconds. 0h 27min 36s
Found 664579 primes. Should be 664579.
3 changes: 3 additions & 0 deletions circuitpython/v5.2_esp32c3/100000000.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
espressif_esp32c3_devkitm_1_n4
Primes to 100000000 took 34241.7 seconds. 9h 30min 41s
Found 5761455 primes. Should be 5761455.
3 changes: 3 additions & 0 deletions circuitpython/v5.2_esp32c3/1000000000.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
espressif_esp32c3_devkitm_1_n4
Primes to 1000000000 took 757171.0 seconds. 210h 19min 30s
Found 50847534 primes. Should be 123456789.
3 changes: 3 additions & 0 deletions circuitpython/v5.2_esp32c3/25000000.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
espressif_esp32c3_devkitm_1_n4
Primes to 25000000 took 5457.0 seconds. 1h 30min 57s
Found 1565927 primes. Should be 1565927.
120 changes: 120 additions & 0 deletions circuitpython/v5.2_esp32c3/code_DevKitM-1_C3N4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# prime v5.3 2023-12-14 for ESP32-C3-DevKitM-1 with ESP32-C3N4
# cycles through limits and writes to the filesystem

import math, time, digitalio, board, os

scope = [100, 1000, 10000, 100000, 1000000, 10000000, 25000000, 100000000, 1000000000]
reference = [25, 168, 1229, 9592, 78498, 664579, 1565927, 5761455, 123456789]
time_calc = [0, 0, 0, 0, 0, 0, 0, 0, 0]

led = digitalio.DigitalInOut(board.IO4)
led.direction = digitalio.Direction.OUTPUT
led.value = True
led2 = digitalio.DigitalInOut(board.IO5)
led2.direction = digitalio.Direction.OUTPUT
led2.value = True

def is_prime(number):
global found
flag_prime = 1
for divider in range(3, int(math.sqrt(number)) + 1, 2):
if number % divider == 0:
flag_prime = 0
break
return flag_prime

def find_primes(largest):
global primes
global found
for number in range(11, largest + 1, 2):
if is_prime(number) > 0:
found += 1
primes.append(number)

def is_prime_fast(number):
global found
flag_prime = 1
largest_divider = int(math.sqrt(number)) + 1
for divider in primes:
if number % divider == 0:
flag_prime = 0
break
if divider > largest_divider:
break
return flag_prime

def elapsed_time(seconds):
hours = int(seconds/3600)
minutes = int(seconds/60 - hours*60)
sec = int(seconds - minutes*60 - hours*3600)
return(f"{hours}h {minutes}min {sec}s")

def lightshow():
led.value = True
led2.value = False
for i in range(10):
led2.value = led.value
led.value = not led.value
time.sleep(0.002)

if __name__ == "__main__":
lightshow()
for i in range(len(scope)):
last = scope[i]
found = 4 # we start from 11, know 2, 3, 5, 7
primes = [3, 5, 7] # exclude 2 since we only test odd numbers
print(f"\nPrime numbers to {last} in v5.3 on {board.board_id}")
start = time.monotonic()
dot = start
column = 1
largest_divider = int(math.sqrt(last))
if largest_divider % 2 == 0:
largest_divider += 1
print(f'First find prime dividers up to {largest_divider}.')
find_primes(largest_divider)
print(f'Found {found} primes, now use them als dividers.')
for number in range(largest_divider + 2, last, 2):
found += is_prime_fast(number)
if (time.monotonic() - dot) > 2:
print(".", end="")
dot = time.monotonic()
column += 1
if column % 2 == 0:
led.value = True
led2.value = not led.value
else:
led.value = False
led2.value = not led.value
if column > 30:
t = elapsed_time(time.monotonic() - start)
print(f" {t} - {number} {int(number*100/last)}% ")
column = 1
duration = time.monotonic() - start
print(f'This took: {duration} seconds. {elapsed_time(duration)}')
print(f'Found {found} primes.')
filename = "/" + str(last) + ".txt"
try:
with open(filename, "w") as fp:
fp.write(board.board_id)
fp.write(f'\nPrimes to {last} took {duration} seconds.')
fp.write(f'\nFound {found} primes. Should be {reference[i]}.')
print('Exported to filesystem ')
except:
print("Can't write to the filesystem. Press reset and after that the boot button in the first 5 seconds")
#print(f'Primes to {last} took {(end - start)} seconds.')
#print(f'Found {found} primes. Should be {reference[i]}.')
time_calc[i] = duration
print('\nWrite summary')
try:
with open("summary.txt", "w") as fp:
fp.write(f'Primes calculation in Circuitpython v5.2 2023/12/11\n')
fp.write(board.board_id)
fp.write('\n last time in seconds\n')
for i in range(len(time_calc)):
fp.write(f' {scope[i]} {time_calc[i]}\n')
print('Exported to filesystem ')
except:
print("Can't write to the filesystem. Press reset and after that the boot button in the first 5 seconds")

while True:
lightshow()
120 changes: 120 additions & 0 deletions circuitpython/v5.2_esp32c3/code_luatos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# prime v5.3 2023-12-14 for luatos esp32c3
# cycles through limits and writes to the filesystem

import math, time, digitalio, board, os

scope = [100, 1000, 10000, 100000, 1000000, 10000000, 25000000, 100000000, 1000000000]
reference = [25, 168, 1229, 9592, 78498, 664579, 1565927, 5761455, 123456789]
time_calc = [0, 0, 0, 0, 0, 0, 0, 0, 0]

led = digitalio.DigitalInOut(board.IO4)
led.direction = digitalio.Direction.OUTPUT
led.value = True
led2 = digitalio.DigitalInOut(board.IO5)
led2.direction = digitalio.Direction.OUTPUT
led2.value = True

def is_prime(number):
global found
flag_prime = 1
for divider in range(3, int(math.sqrt(number)) + 1, 2):
if number % divider == 0:
flag_prime = 0
break
return flag_prime

def find_primes(largest):
global primes
global found
for number in range(11, largest + 1, 2):
if is_prime(number) > 0:
found += 1
primes.append(number)

def is_prime_fast(number):
global found
flag_prime = 1
largest_divider = int(math.sqrt(number)) + 1
for divider in primes:
if number % divider == 0:
flag_prime = 0
break
if divider > largest_divider:
break
return flag_prime

def elapsed_time(seconds):
hours = int(seconds/3600)
minutes = int(seconds/60 - hours*60)
sec = int(seconds - minutes*60 - hours*3600)
return(f"{hours}h {minutes}min {sec}s")

def lightshow():
led.value = True
led2.value = False
for i in range(10):
led2.value = led.value
led.value = not led.value
time.sleep(0.002)

if __name__ == "__main__":
lightshow()
for i in range(len(scope)):
last = scope[i]
found = 4 # we start from 11, know 2, 3, 5, 7
primes = [3, 5, 7] # exclude 2 since we only test odd numbers
print(f"\nPrime numbers to {last} in v5.3 on {board.board_id}")
start = time.monotonic()
dot = start
column = 1
largest_divider = int(math.sqrt(last))
if largest_divider % 2 == 0:
largest_divider += 1
print(f'First find prime dividers up to {largest_divider}.')
find_primes(largest_divider)
print(f'Found {found} primes, now use them als dividers.')
for number in range(largest_divider + 2, last, 2):
found += is_prime_fast(number)
if (time.monotonic() - dot) > 2:
print(".", end="")
dot = time.monotonic()
column += 1
if column % 2 == 0:
led.value = True
led2.value = not led.value
else:
led.value = False
led2.value = not led.value
if column > 30:
t = elapsed_time(time.monotonic() - start)
print(f" {t} - {number} {int(number*100/last)}% ")
column = 1
duration = time.monotonic() - start
print(f'This took: {duration} seconds. {elapsed_time(duration)}')
print(f'Found {found} primes.')
filename = "/" + str(last) + ".txt"
try:
with open(filename, "w") as fp:
fp.write(board.board_id)
fp.write(f'\nPrimes to {last} took {duration} seconds.')
fp.write(f'\nFound {found} primes. Should be {reference[i]}.')
print('Exported to filesystem ')
except:
print("Can't write to the filesystem. Press reset and after that the boot button in the first 5 seconds")
#print(f'Primes to {last} took {(end - start)} seconds.')
#print(f'Found {found} primes. Should be {reference[i]}.')
time_calc[i] = duration
print('\nWrite summary')
try:
with open("summary.txt", "w") as fp:
fp.write(f'Primes calculation in Circuitpython v5.2 2023/12/11\n')
fp.write(board.board_id)
fp.write('\n last time in seconds\n')
for i in range(len(time_calc)):
fp.write(f' {scope[i]} {time_calc[i]}\n')
print('Exported to filesystem ')
except:
print("Can't write to the filesystem. Press reset and after that the boot button in the first 5 seconds")

while True:
lightshow()
18 changes: 9 additions & 9 deletions circuitpython/v5.2_esp32c3/summary.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Primes calculation in Circuitpython v5.2 2023/12/11
espressif_esp32c3_devkitm_1_n4
last time in seconds
100 0.0170898
1000 0.046875
10000 0.436035
100000 5.64502
1000000 98.019
10000000 1840.33
25000000 0
100000000 0
1000000000 0
100 0.0170002
1000 0.046999
10000 0.429998
100000 5.668
1000000 89.739
10000000 1656.41
25000000 5457.0
100000000 34241.7
1000000000 757171.0

0 comments on commit 6ae10cd

Please sign in to comment.