// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/_images/esp32-devkitC-v4-pinout.png
#define TIMING_PIN 23

#include <Arduino.h>
#include <WiFi.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");

  pinMode(TIMING_PIN, OUTPUT);

  WiFi.begin("Wokwi-GUEST", "", 6);
  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    Serial.print(".");
  }
  Serial.println(" Connected!");
}


static inline void start() {
//    noInterrupts();
  digitalWrite(TIMING_PIN, HIGH);
  //GPIO.out_w1ts = 1 << TIMING_PIN;
}

static inline void stop() {
  digitalWrite(TIMING_PIN, LOW);
  //GPIO.out_w1tc = 1 << TIMING_PIN;
//  interrupts();
}


unsigned long lastLoop_ms = 2000;
unsigned long period_ms = 3;

void loop() {
  if (millis() - lastLoop_ms > period_ms) {
    lastLoop_ms += period_ms;

    start(); // start(); stop(); 250 +/- 1 ns (a few exceptions ~24ns at start !)
    // volatile uint32_t x = micros(); // 5250 +/- 2ns
    // volatile uint32_t y = millis();    
    // 10875ns, but ~periodically outliers 1300 - 3000ns during the 1st second (nowifi)
    // 10875ns, but irregular outliers 1100 - 6500ns during the whole recording session
    
    // volatile float f = millis();    // 
    // volatile float f = millis() * .001f; // 
    //Serial.println(millis());       // (WiFi) 183µs avg; mostly 178-184µs but few outliers at 77-90µs!
    volatile float f = sin(millis());  // (WiFi) 203µs avg; mostly 180-220µs but 1% outliers at 20-30µs
    // volatile float f = sqrt(millis());   // 30 - 36µs
    stop();
  }
}
timing-measurementBreakout
D0D1D2D3D4D5D6D7GNDLOGIC