B4R Question esp8266 (nodemcu v3) vs esp32 (esp wroom 32)

giggetto71

Active Member
Licensed User
Longtime User
HI,
I am facing a strange result with a very simple test.
I am running a very simple code.

B4X:
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    
    Dim ii As ULong, Counter As ULong = 0, StartMils As ULong, EndMils As ULong
    StartMils = Millis
    Log("begin")
    Log(Millis)
    For ii = 1 To 100000000
        Counter = Counter +1
    Next
    Log("completed")
    Log(Counter)
    Log(Millis)
    EndMils = Millis - StartMils
    Log("it took:")
    Log(EndMils)
End Sub

I run the same code using B4R 3.31 and Arduino 1.8.13.
Basically I want to measure how long the above code takes on a esp8266 device (nodemcu v3) and on a esp32 device (esp wroom 32). Specifically the detected chips by the log when I dowload are ESP8266EX and ESP32D0WDQ6 respectively.
When I run the code on the esp8266 I get:

begin
78
completed
100000000
80
it took:
4

When I run it on the EPS32 device, I get:


begin
40
completed
100000000
49
it took:
14


In other words it seems that the ESP32 is way slower than the ESP8266, while I would expected the other way around.
Am I missing somenthing?
thanks!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The correct way to check it is with this code:
B4X:
StartMils = Millis
Log(Millis)
For ii = 1 To 100000000
    Counter = Counter +1
Next
EndMils = Millis - StartMils

The logs should be before or after this code as you don't want the log flushing to affect the measurements. I get 3ms when running on ESP32.
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
ok. I get 2 ms now. thanks.
One more problem is that if I try to increase the for loop from 1e8 to 1e9 it fails to download it to upload to the device. that's strange because the type is ULong..any idea why?
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
I think I got some insight. it seems it's an known issue and it does have to do with the code at all.
The error you get is "failed-to-connect-to-esp32-timed-out-waiting-for-packet-header" and searching a bit on it I found this:


Basically in some cases the only way to upload the code is to press the "boot" button on the device.
not sure why in my example, if I do the for for 1e8 it never fails to upload while increasing it it falls into the time out in a repeatable way.
 
Upvote 0
Top