Page 1 of 1

New to ESP32; Question of Performance

Posted: Fri Dec 28, 2018 12:24 pm
by psionprime
I am evaluating an ESP32 via an Adafruit Huzzah ESP32 board using the Arduino IDE and Esspressif Systems Arduino Board Manager libraries.

I am looking at trying micropython on the board and, for giggles, ran a quickie benchmark just to see (off of https://github.com/micropython/micropyt ... erformance)

Code: Select all

// this code is for testing Adafruit Huuzah ESP32 Feather

#include <Arduino.h>  
#include "WiFi.h"

void setup() {
    // turn off ESP32 radios to save battery
    WiFi.mode(WIFI_OFF);
    btStop();    
    
    Serial.begin(115200);  
    uint32_t endTime = millis() + 10000;  
    uint32_t count = 0;  
    while (millis() < endTime)  
        count++;  
    Serial.print("");  
    Serial.print("Count: ");  
    Serial.println(count);  
}  
void loop() {  
}  
The results came back as 8,269,925 (repeatable within 5 counts). The Teensy 3.1: (96Mhz ARM), per the site, returned 95,835,923 counts. Wow ! I was expecting a lot more from a 240MHz processor.

Does this sound right ? Is there anything I can tweak on the Arduino side ? I am thinking I may need to use a GNU tool chain but wanted to run this by you guys first.

Re: New to ESP32; Question of Performance

Posted: Fri Dec 28, 2018 3:37 pm
by ESP_Sprite
You're effectively calculating the performance of the millis() function here, as that will have the most overhead. As you may imagine, that function is not really created with lightning-fast runtime speed in mind: for instance, the teensy may just check a timer register, while the ESP32 emulates it using gettimeofday() which has some overhead with locks etc. Suggest you try some real code to figure out the actual performance.

Re: New to ESP32; Question of Performance

Posted: Fri Dec 28, 2018 3:53 pm
by psionprime
Do you have some real code ? I will look for a compatible drystone or similar bench though perhaps a dev here will have something to share that shows off the dual cores :) eg., FreeRTOS working with the cores to schedule tasks etc. sounds cool.

I dunno, as I said, exploring the chip. You did give insight, if true, the emulation of a basic timing function being extremely inefficient is not the greatest of showcases. Now I need to dig into what timers are available and how to use them. All good.

Re: New to ESP32; Question of Performance

Posted: Fri Dec 28, 2018 11:41 pm
by fivdiAtESP32
FWIW, at 240MHz a counter can be incremented about 265 million times in 10 seconds.

Test code:

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_timer.h"

void test() {
  uint64_t starttime = esp_timer_get_time();
  uint32_t count = 0;
  while (count < 265693020) {
    count++;
  }
  uint64_t endtime = esp_timer_get_time();
  printf("Counted to %u in %lld microseconds\n", count, (endtime - starttime));
}

void app_main() {
  while (true) {
    test();
    vTaskDelay(1 / portTICK_PERIOD_MS);
  }
}
Output:

Code: Select all

Counted to 265693020 in 9984154 microseconds
Counted to 265693020 in 9999967 microseconds
Counted to 265693020 in 9999967 microseconds
Counted to 265693020 in 9999967 microseconds
Counted to 265693020 in 9999967 microseconds
Counted to 265693020 in 9999997 microseconds
Counted to 265693020 in 9999967 microseconds
Counted to 265693020 in 9999967 microseconds
Counted to 265693020 in 9999967 microseconds
Counted to 265693020 in 10000401 microseconds
Counted to 265693020 in 10000861 microseconds
Counted to 265693020 in 10000835 microseconds
Counted to 265693020 in 10000835 microseconds
Counted to 265693020 in 10000835 microseconds
Counted to 265693020 in 10000840 microseconds
Counted to 265693020 in 10000861 microseconds
Counted to 265693020 in 10000835 microseconds
Counted to 265693020 in 10000835 microseconds
Counted to 265693020 in 10000835 microseconds
Counted to 265693020 in 10000835 microseconds
Counted to 265693020 in 10001314 microseconds
Counted to 265693020 in 10002665 microseconds
Counted to 265693020 in 10019459 microseconds
Counted to 265693020 in 10000835 microseconds
Counted to 265693020 in 10000835 microseconds
Counted to 265693020 in 10000861 microseconds
Counted to 265693020 in 10000835 microseconds
Counted to 265693020 in 10000835 microseconds

Re: New to ESP32; Question of Performance

Posted: Tue Jan 08, 2019 5:18 am
by richhas
Make 'count' a 64-bit var.