// Code from How Fast Does Your Arduino Code Run?
// https://youtu.be/tnfeMCyLZSo,
// talofer99: port manipulation on arduino

void setup()  {   // void codeRunMeasured()
  Serial.begin(115200);
  pinMode(13, OUTPUT);

  //** Set up Timer 1 to count every single clock cycle
  TCCR1A = 0;
  TCCR1B = bit(CS10); // or ( =1 << CS10;)
  TCNT1 = 0;

  /* Code under test */

  //digitalWrite(13, HIGH);  // slower 38cycles, 2,38us
  //PORTB = bit(5);          // faster 2cycles, 0,12us
  //delayMicroseconds(501);    // 7997cycles, 499,81us
  //delayMicroseconds(52);        // 813cycles, 50,81us
  //delayMicroseconds(51);        // 797cycles, 49,81us
  delayMicroseconds(5);        // 61cycles, 3,81us
  //delayMicroseconds(5074);        // 16013cycles, 1000,81us
  //delay(5000);                // 46119cycles, 2882,44us ????
  //delay(50);                    // 13567cycles, 849,81us  ????

  /* End of code under test */

  //** Print the result
  unsigned long value = TCNT1;
  Serial.print("Cycles: ");
  Serial.println(value - 2);
  Serial.print((float)(value - 2) / 16);
  Serial.println(" usec.");
  // If your frequency is 16 Mhz then (1/f = T) it means that 
  // 1 cycle takes 1/16 000 000 = 62.5 ns 
  // and if you have 38 cycles. 38 * 62.5 ns = 2375 ns = 2.38 micro seconds.
}

void loop() {
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
r1:1
r1:2
led:A
led:C