I am a novice at this and wanted to see just how quickly (or efficiently) the compiler is wrt to, say, a simple pin write function. So I have two super simple sketches (SSS), and I monitor the pin toggle speed with an oscilloscope:
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13,HIGH);
digitalWrite(13,LOW);
digitalWrite(13,HIGH);
digitalWrite(13,LOW);
}
******** Cycle time = 7.7us.
Now use some simple instructions:
void loop() {
PORTB |= B00100000;
PORTB &= B11011111;
PORTB |= B00100000;
PORTB &= B11011111;
}
******** Cycle time = 250ns . . . . that is more than 30X faster . . . 2 cycles each to be exact! Just what you expected. This is not a good indictment if you are looking for any kind of speed. Why is it so bad?