diff --git a/arduino/v5.3/prime_logging_esp32/results.txt b/arduino/v5.3/prime_logging_esp32/results.txt index f1d8a5e..5416575 100644 --- a/arduino/v5.3/prime_logging_esp32/results.txt +++ b/arduino/v5.3/prime_logging_esp32/results.txt @@ -1,17 +1,21 @@ Calculating prime numbers in Arduino C v5.4.2023 -2023/12/23 -ESP32-S3 OTG USB with 240 MHz +2023/12/24 +ESP32 with 240 MHz + +Get previous results for this ESP32: + 100 0.000390 + 1000 0.002854 + 10000 0.029392 + 100000 0.321495 + 1000000 3.828875 + 10000000 52.244022 + 25000000 155.919083 + 100000000 857.574036 + 1000000000 0.000000 + 2147483647 0.000000 + 4294967295 0.000000 + -Get previous results for this ESP32-S3: - last seconds - 100 0.000348 - 1000 0.018474 - 10000 0.028547 - 100000 0.310781 - 1000000 3.670793 - 10000000 49.427952 - 25000000 146.725739 - 100000000 800.481140 1000000000 15763.267578 - 4h 22min 43s 2147483647 46706.203125 - 12h 58min 26s 4294967295 119194.734375 - 33h 6min 34s diff --git a/arduino/v5.3/prime_logging_esp32c3_neopixel/prime_logging_esp32c3_neopixel.ino b/arduino/v5.3/prime_logging_esp32c3_neopixel/prime_logging_esp32c3_neopixel.ino new file mode 100644 index 0000000..95ee2f8 --- /dev/null +++ b/arduino/v5.3/prime_logging_esp32c3_neopixel/prime_logging_esp32c3_neopixel.ino @@ -0,0 +1,271 @@ +/* Prime numbers in Arduino C v5.4 2023/12/21 for esp32-c3 */ +#include +#include +#include +#include + +#define LED_PIN 8 +#define NEOPIXEL_PIN LED_PIN +Adafruit_NeoPixel pixels(1, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800); + +double start; +int column = 10; +int found = 4; // we already know 2, 3, 5, 7 +int divisors = found; +int primes[6550] = {3, 5, 7}; +int RED[3] = {64, 0, 0}; +int GREEN[3] = {0, 64, 0}; +int BLUE[3] = {0, 0, 64}; + +int is_prime(int number) { + int prime = 1; + for (int divider = 3; divider < (int)(sqrt(number)) + 1; divider += 2) + { + if (number % divider == 0) + { + prime = 0; + break; + } + } + return prime; +} + +int find_primes(int limit) { + for(int number=11; number < limit + 1; number += 2) { + if( is_prime(number) == 1) { + primes[found - 1] = number; + found++; + } + } + primes[found - 1] = limit; + divisors = found - 1; + return 1; +} + +int is_prime_fast(uint32_t number) { + int largest_divider = (int)(sqrt(number)); + int flag_prime = 1; + // Serial.print(number); + // Serial.print(" - "); + for(int i=0; i < divisors; i++) + { + // Serial.print(primes[i]); + // Serial.print(" "); + if(number % primes[i] == 0) + { + flag_prime = 0; + break; + } + if(primes[i] > largest_divider) + { + break; + } + } + // Serial.print("\n"); + return flag_prime; +} + +void elapsed_time(int seconds) { + int hours = (int)seconds/3600; + int minutes = (int)(seconds/60 - hours*60); + int sec = (int)(seconds - minutes*60 - hours*3600); + Serial.print(" "); + Serial.print(hours); + Serial.print("h "); + Serial.print(minutes); + Serial.print("min "); + Serial.print(sec); + Serial.print("s "); +} + +void led(int RGB[]) { + pixels.setPixelColor(0, pixels.Color(RGB[0], RGB[1], RGB[2])); + pixels.show(); +} + + + +void setup() { + Serial.begin(74880); + pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) + led(RED); + for (int i = 0; i < 3; i++) { + Serial.print("."); + delay(1000); + } + led(BLUE); + const uint32_t scope[] = {100, 1000, 10000, 100000, 1000000, 10000000, 25000000, 100000000, 1000000000, 2147483647, 4294967295}; + const int reference[] = {25, 168, 1229, 9592, 78498, 664579, 1565927, 5761455, 50847534, 105097564, 203280221}; + + + + // previous run + const char* pref[] = {"p100", "p1000", "p10000", "p100000", "p1000000", "p10000000", "p25000000", "p100000000", "p1000000000", "p2147483647", "p4294967295"}; + Preferences preferences; + preferences.begin("prime", true); + Serial.print("\nGet previous results for this ESP32-C3:\n"); + Serial.print(" last seconds \n"); + for(int i = 0; i < 11; i++) { + int spaces = 11 - (int)log10(scope[i]); + for(int j = 0; j < spaces; j++) { + Serial.print(" "); + } + Serial.print(scope[i]); + Serial.print(" "); + Serial.print(preferences.getFloat(pref[i], 0), 6); + Serial.print("\n"); + } + preferences.end(); + delay(1000); + led(GREEN); + + + + // start calculating with micros() until 100 million + for (int i = 0; i < 8; i++) // 8 + { + int last = scope[i]; + found = 4; // we already know 2, 3, 5, 7 + Serial.println("\n\nPrime v5.4 in Arduino C - 2023/12/21"); + Serial.print("Calculating prime numbers until "); + Serial.println(last); + start = micros(); // use micros() for more precision + int largest_divider = (int)(sqrt(last)); + if(largest_divider % 2 == 0) + { + largest_divider += 1; + } + find_primes(largest_divider); + Serial.print("Found "); + Serial.print(found); + Serial.print(" primes until "); + Serial.print(largest_divider); + Serial.print(" to use as divisors.\n"); + int dot = millis(); + int column = 0; + for(int number = largest_divider + 2; number < last; number += 2) + { + found += is_prime_fast(number); + if((millis() - dot) > 1000) { + Serial.print("."); + dot = millis(); + column += 1; + if(column % 2 == 0) { + led(RED); + } + else + { + led(GREEN); + } + if(column > 40) { + column = 0; + elapsed_time(dot/1000); + Serial.print(" - "); + Serial.print(number); + Serial.print(" "); + Serial.print((int)(number / (last / 100))); + Serial.print("% \n"); + } + } + } + float duration = (micros() - start)/1000000; + if(duration > 2) { + Serial.print("\n"); + } + Serial.print("Found "); + Serial.print(found); + Serial.print(" prime numbers. It should be "); + Serial.print(reference[i]); + Serial.print(".\nThis took "); + Serial.print(duration, 6); + Serial.print(" seconds."); + elapsed_time(duration); + preferences.begin("prime", false); + preferences.putFloat(pref[i], duration); + preferences.end(); + } + + + + + + // start calculating with millis() from 1 billion + for (int i = 8; i < 11; i++) + { + uint32_t last = scope[i]; + found = 4; // we already know 2, 3, 5, 7 + Serial.println("\n\nPrime v5.0 in Arduino C - 2023/12/20"); + Serial.print("Calculating prime numbers until "); + Serial.println(last); + start = millis(); + int largest_divider = (int)(sqrt(last)); + if(largest_divider % 2 == 0) + { + largest_divider += 1; + } + find_primes(largest_divider); + Serial.print("Found "); + Serial.print(found); + Serial.print(" primes until "); + Serial.print(largest_divider); + Serial.print(" to use as divisors.\n"); + int dot = millis(); + int column = 0; + for(uint32_t number = largest_divider + 2; number < last; number += 2) + { + found += is_prime_fast(number); + if((millis() - dot) > 1000) { + Serial.print("."); + dot = millis(); + column += 1; + if(column % 2 == 0) { + led(RED); + } + else + { + led(GREEN); + } + if(column > 40) { + column = 0; + elapsed_time(dot/1000); + Serial.print(" - "); + Serial.print(number); + Serial.print(" "); + Serial.print((int)(number / (last / 100))); + Serial.print("% \n"); + } + } + } + float duration = (millis() - start)/1000; + if(duration > 2) { + Serial.print("\n"); + } + Serial.print("Found "); + Serial.print(found); + Serial.print(" prime numbers. It should be "); + Serial.print(reference[i]); + Serial.print(".\nThis took "); + Serial.print(duration, 6); + Serial.print(" seconds."); + elapsed_time(duration); + preferences.begin("prime", false); + preferences.putFloat(pref[i], duration); + preferences.end(); + } + preferences.end(); + Serial.print("\n"); +} + +void loop() { // program finished, just keep printing some dots + for(int i = 0; i < 80; i++) { + Serial.print("."); + for(int x = 0; x < 100; x++) { + led(BLUE); + delay(30); + pixels.clear(); + pixels.show(); + delay(20); + } + } + Serial.print(".\n"); +} diff --git a/arduino/v5.3/prime_logging_esp32c3_neopixel/results.txt b/arduino/v5.3/prime_logging_esp32c3_neopixel/results.txt new file mode 100644 index 0000000..d86392a --- /dev/null +++ b/arduino/v5.3/prime_logging_esp32c3_neopixel/results.txt @@ -0,0 +1,17 @@ +Calculating prime numbers in Arduino C v5.4.2023 +2023/12/25 +ESP32-C3 OTG USB with 160 MHz + +Get previous results for this ESP32-C3: + last seconds + 100 0.000528 + 1000 0.005168 + 10000 0.055167 + 100000 0.620651 + 1000000 7.621645 + 10000000 106.675552 + 25000000 318.646759 + 100000000 1751.800415 + 1000000000 33369.484375 + 2147483647 91127.843750 + 4294967295 228788.000000 \ No newline at end of file diff --git a/circuitpython/v5.3_esp32c3_luatos/100.txt b/circuitpython/v5.3_esp32c3_luatos/100.txt index 99ee1ae..ecf6f5c 100644 --- a/circuitpython/v5.3_esp32c3_luatos/100.txt +++ b/circuitpython/v5.3_esp32c3_luatos/100.txt @@ -1,3 +1,3 @@ -vcc_gnd_yd_rp2040 -Primes to 100 took 0.00799561 seconds. +luatos_core_esp32c3 +Primes to 100 took 0.0109863 seconds. Found 25 primes. Should be 25. \ No newline at end of file diff --git a/circuitpython/v5.3_esp32c3_luatos/1000.txt b/circuitpython/v5.3_esp32c3_luatos/1000.txt index 9788ae1..26a5f82 100644 --- a/circuitpython/v5.3_esp32c3_luatos/1000.txt +++ b/circuitpython/v5.3_esp32c3_luatos/1000.txt @@ -1,3 +1,3 @@ -vcc_gnd_yd_rp2040 -Primes to 1000 took 0.0639954 seconds. +luatos_core_esp32c3 +Primes to 1000 took 0.0579834 seconds. Found 168 primes. Should be 168. \ No newline at end of file diff --git a/circuitpython/v5.3_esp32c3_luatos/10000.txt b/circuitpython/v5.3_esp32c3_luatos/10000.txt index 8160819..7894963 100644 --- a/circuitpython/v5.3_esp32c3_luatos/10000.txt +++ b/circuitpython/v5.3_esp32c3_luatos/10000.txt @@ -1,3 +1,3 @@ -vcc_gnd_yd_rp2040 -Primes to 10000 took 0.758003 seconds. +luatos_core_esp32c3 +Primes to 10000 took 0.572998 seconds. Found 1229 primes. Should be 1229. \ No newline at end of file diff --git a/circuitpython/v5.3_esp32c3_luatos/100000.txt b/circuitpython/v5.3_esp32c3_luatos/100000.txt index 1c7cc2a..c5f5792 100644 --- a/circuitpython/v5.3_esp32c3_luatos/100000.txt +++ b/circuitpython/v5.3_esp32c3_luatos/100000.txt @@ -1,3 +1,3 @@ -vcc_gnd_yd_rp2040 -Primes to 100000 took 10.167 seconds. +luatos_core_esp32c3 +Primes to 100000 took 7.22998 seconds. Found 9592 primes. Should be 9592. \ No newline at end of file diff --git a/circuitpython/v5.3_esp32c3_luatos/1000000.txt b/circuitpython/v5.3_esp32c3_luatos/1000000.txt index b0ef192..508f233 100644 --- a/circuitpython/v5.3_esp32c3_luatos/1000000.txt +++ b/circuitpython/v5.3_esp32c3_luatos/1000000.txt @@ -1,3 +1,3 @@ -vcc_gnd_yd_rp2040 -Primes to 1000000 took 156.987 seconds. +luatos_core_esp32c3 +Primes to 1000000 took 106.811 seconds. Found 78498 primes. Should be 78498. \ No newline at end of file diff --git a/circuitpython/v5.3_esp32c3_luatos/10000000.txt b/circuitpython/v5.3_esp32c3_luatos/10000000.txt new file mode 100644 index 0000000..00bc0cf --- /dev/null +++ b/circuitpython/v5.3_esp32c3_luatos/10000000.txt @@ -0,0 +1,3 @@ +luatos_core_esp32c3 +Primes to 10000000 took 1975.6 seconds. +Found 664579 primes. Should be 664579. \ No newline at end of file diff --git a/circuitpython/v5.3_esp32c3_luatos/100000000.txt b/circuitpython/v5.3_esp32c3_luatos/100000000.txt new file mode 100644 index 0000000..8878948 --- /dev/null +++ b/circuitpython/v5.3_esp32c3_luatos/100000000.txt @@ -0,0 +1,3 @@ +luatos_core_esp32c3 +Primes to 100000000 took 38587.1 seconds. +Found 5761455 primes. Should be 5761455. \ No newline at end of file diff --git a/circuitpython/v5.3_esp32c3_luatos/1000000000.txt b/circuitpython/v5.3_esp32c3_luatos/1000000000.txt new file mode 100644 index 0000000..5965cd3 --- /dev/null +++ b/circuitpython/v5.3_esp32c3_luatos/1000000000.txt @@ -0,0 +1,3 @@ +luatos_core_esp32c3 +Primes to 1000000000 took 826497.0 seconds. +Found 50847534 primes. Should be 123456789. \ No newline at end of file diff --git a/circuitpython/v5.3_esp32c3_luatos/25000000.txt b/circuitpython/v5.3_esp32c3_luatos/25000000.txt new file mode 100644 index 0000000..04e4f14 --- /dev/null +++ b/circuitpython/v5.3_esp32c3_luatos/25000000.txt @@ -0,0 +1,3 @@ +luatos_core_esp32c3 +Primes to 25000000 took 6334.8 seconds. +Found 1565927 primes. Should be 1565927. \ No newline at end of file diff --git a/circuitpython/v5.3_esp32c3_luatos/code.py b/circuitpython/v5.3_esp32c3_luatos/code.py index d62edbd..b343146 100644 --- a/circuitpython/v5.3_esp32c3_luatos/code.py +++ b/circuitpython/v5.3_esp32c3_luatos/code.py @@ -1,4 +1,4 @@ -# prime v5.3 2023-12-14 for luatos esp32c3 +# prime v5.3 2023-12-25 for luatos esp32c3 # cycles through limits and writes to the filesystem import math, time, digitalio, board, os @@ -52,8 +52,7 @@ def lightshow(): time.sleep(0.2) if __name__ == "__main__": - lightshow() - for i in range(len(scope)): + for i in range(len(scope)): # 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 @@ -99,7 +98,7 @@ def lightshow(): 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(f'Primes calculation in Circuitpython v5.3 2023/12/14\n') fp.write(board.board_id) fp.write('\n last time in seconds\n') for i in range(len(time_calc)): @@ -110,3 +109,4 @@ def lightshow(): while True: lightshow() + diff --git a/circuitpython/v5.3_esp32c3_luatos/summary.txt b/circuitpython/v5.3_esp32c3_luatos/summary.txt new file mode 100644 index 0000000..3393c6c --- /dev/null +++ b/circuitpython/v5.3_esp32c3_luatos/summary.txt @@ -0,0 +1,12 @@ +Primes calculation in Circuitpython v5.3 2023/12/14 +luatos_core_esp32c3 + last time in seconds + 100 0.0109863 + 1000 0.0579834 + 10000 0.572998 + 100000 7.22998 + 1000000 106.811 + 10000000 1975.6 + 25000000 6334.8 + 100000000 38587.1 + 1000000000 826497.0