ja, ich habe ja schon mal einen Benchmarktest für verschiedene MCUs geschrieben, könnte ich mal machen
- - - Aktualisiert - - -
edit: Code aktualisiert nach Ceos' Einwand (s.u.!)
Code:
#define TimerMS() millis() //for cross plattform compatib
uint32_t time0;
long test_Int_multdiv2() {
uint32_t x,y;
volatile uint32_t s;
for(y=0;y<10000;y++) {
s=11;
for(x=1;x<=16;x++) { s*=2;}
for(x=16; x>0;x--) { s/=2;}
s=7;
for(x=1;x<=8;x++) { s*=8;}
for(x=8; x>0;x--) { s/=8;}
}
return s;
}
long test_Int_shl_shr() {
uint32_t x,y;
volatile uint32_t s;
for(y=0;y<10000;y++) {
s=11;
for(x=1;x<=16;x++) { s=(s<<1);}
for(x=16; x>0;x--) { s=(s>>1);}
s=7;
for(x=1;x<=8;x++) { s=(s<<3);}
for(x=8; x>0;x--) { s=(s>>3);}
}
return s;
}
// *SNIP*
time0=TimerMS();
s=test_Int_multdiv2();
runtime[0]=TimerMS()-time0;
sprintf (buf, "%3d %9ld Int_multdiv2", 0, runtime[0]); Serial.println( buf);
time0=TimerMS();
s=test_Int_shl_shr();
runtime[1]=TimerMS()-time0;
sprintf (buf, "%3d %9ld Int_shl_shr", 1, runtime[1]); Serial.println( buf);
Ergebnis: doch identisch, anders als vermutet (Angaben in ms):
Plattform: AVR (Arduino Mega2560, 16 MHz)
Code:
start test
0 1220 Int_multdiv2
1 1220 Int_shl_shr
Plattform: ARM Cortex M0 (Adafruit Itsybitsy M0, 48 MHz)
Code:
start test
0 93 Int_multdiv2
1 93 Int_shl_shr
Plattform: ARM Cortex M3 (Arduino Due, 84MHz)
Code:
start test
0 49 Int_multdiv2
1 49 Int_shl_shr
Pattform: ESP8266 (nodeMCU, Xtensa LX106, 80 MHz)
Code:
start test
start test
0 56 Int_multdiv2
1 55 Int_shl_shr
edit:
gleiches Ergebnis auch für Zuweisung an 2. Variable:
Code:
long test_Int_multdiv2() {
uint32_t x,y;
volatile uint32_t s,t;
for(y=0;y<10000;y++) {
s=11;
for(x=1;x<=16;x++) { t=s*2;}
for(x=16; x>0;x--) { t=s/2;}
s=7;
for(x=1;x<=8;x++) { t=s*8;}
for(x=8; x>0;x--) { t=s/8;}
}
return s;
}
long test_Int_shl_shr() {
uint32_t x,y;
volatile uint32_t s,t;
for(y=0;y<10000;y++) {
s=11;
for(x=1;x<=16;x++) { t=(s<<1);}
for(x=16; x>0;x--) { t=(s>>1);}
s=7;
for(x=1;x<=8;x++) { t=(s<<3);}
for(x=8; x>0;x--) { t=(s>>3);}
}
return s;
}
Lesezeichen