// Code from How Fast Does Your Arduino Code Run?
// https://youtu.be/tnfeMCyLZSo
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
// Set up Timer 1 to count every single clock cycle
TCCR1A = 0;
TCCR1B = 1 << CS10;
TCNT1 = 0;
/* Code under test */
digitalWrite(LED_BUILTIN, HIGH);
/* End of code under test */
// Print the result
unsigned int value = TCNT1;
Serial.print("Cycles: ");
Serial.println(value - 1);
Serial.print("Microseconds: ");
Serial.println((float)(value - 1) / 16);
}
void loop() {
}