-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Description
Hardware:
Board: ESP-WROVER-32 board
Core Installation/update date: 03/mar/2019 (version 1.0.1)
IDE name: Arduino IDE
Flash Frequency: 80 MHz
PSRAM enabled: yes
Upload Speed: 921600
Computer OS: Windows 10
Description:
I've noticed a very bad performance of the FPU unit. The datasheet says it's only able to work with 32-bit floating point numbers. So, the "float" data type. I prepared a sketch below to see which will work faster: the FPU (using the "float" data type) or the CPU (using the "double" data type). I expect that the "float" data type operations will complete faster than the ones using "double". In reality, the complete opposite of this can be seen ("double" data type operations execute almost 2 times faster!). After searching for this problem on the Internet, I saw that this may be caused by the FPU startup procedure. So, I repeated the same code twice, but the difference has got even bigger!
Sketch
void setup() {
Serial.begin(115200);
float f = 2;
uint32_t st_f = micros();
for(uint64_t i = 0; i < 10000000; i++)
f *= f * (double)f;
Serial.println(f);
Serial.println(String(micros() - st_f));
double d = 2;
uint32_t st_d = micros();
for(uint64_t i = 0; i < 10000000; i++)
d *= d * (double)d;
Serial.println(d);
Serial.println(String(micros() - st_d));
Serial.println("---RETRY---");
f = 2;
st_f = micros();
for(uint64_t i = 0; i < 10000000; i++)
f *= f * (double)f;
Serial.println(f);
Serial.println(String(micros() - st_f));
d = 2;
st_d = micros();
for(uint64_t i = 0; i < 10000000; i++)
d *= d * (double)d;
Serial.println(d);
Serial.println(String(micros() - st_d));
}
void loop() {
}Debug Messages:
inf
6925317
inf
4322672
---RETRY---
inf
7134875
inf
3987262