This is a timestamp library for Arduino to measure execution durations in microseconds or milliseconds resolution.
Any Arduino / ESP8266 board.
Add include file:
#include <Timestamp.h>
Create timestamp object with microseconds resolution:
TimestampMicros timestamp;
Create timestamp object with milliseconds resolution:
TimestampMillis timestamp;
unsigned long duration;
// Start measurement
timestamp.start();
// Do something
duration = timestamp.end();
// Start new measurement
timestamp.start();
// Do something
duration = timestamp.end();
// Start timestamp
timestamp.start();
// Do something and print timstamp
timestamp.print();
// Do something and print timestamp without calling start()
timestamp.print();
The following examples are available:
- Examples | Erriez Timestamp | Microseconds
- Examples | Erriez Timestamp | Milliseconds
Timestamp with microseconds resolution example
Printing this message takes: 768us
And this message takes: 2044us
delayMicroseconds(15) duration: 20us
analogRead() duration: 212us
digitalRead() duration: 4us
Timestamp with milliseconds resolution example
delay(15) takes:
15ms
14ms
16ms
15ms
15ms
16ms
14ms
15ms
16ms
15ms
TimestampMicros uses the function micros(). TimestampMillis uses the function millis().
Please refer to the description of these functions for the maximum possible duration:
- https://www.arduino.cc/reference/en/language/functions/time/micros/
- https://www.arduino.cc/reference/en/language/functions/time/millis/
Please refer to the Wiki page.