I cannot say anything specific about Mbed Studio or VSCode. (I don’t use them.) But, with CLI, we use mbed build profiles to set optimization levels (and others). I guess you can do that on Studio too.
The same code doesn’t mean it always performs the same. You have to compile your code to run it on your target. The actual performance (and code size) depends on the compiler and optimization level.
Here is my little experiment for you. The same code, the same OS (5.15.1), the same microcontroller (LPC1768), and the same compiler (GCC). But, different optimization settings. You can see how they are different.
The code:
#include "mbed.h"
SPI spi(p5, p6, p7);
DigitalOut cs(p8);
int main() {
spi.format(8, 3);
spi.frequency(1000000);
cs = 1;
while (1) {
cs = 0;
spi.write('H');
spi.write('e');
spi.write('l');
spi.write('l');
spi.write('o');
cs = 1;
}
}
Optimization option -O0: 16.55us
Optimization option -O1: 8.35us
Optimization option -O2: 7.75us
Optimization option -O3: 7.3us
So, I suggest your playing around with the optimization settings before you conclude that this is a bug in Mbed Studio.
I would also see if Studio and VSCode use the same compiler.