|
3-phase PV router
|
Exact CPU cycle count of a benchmark loop, whatever its length. More...
#include <Arduino.h>

Go to the source code of this file.
Namespaces | |
| namespace | BenchTimer |
Functions | |
| void | BenchTimer::begin () |
| Starts counting: from the last instruction on, one count per CPU cycle. | |
| uint32_t | BenchTimer::end () |
| The cycles since begin(), its own instructions included. | |
| ISR (TIMER1_OVF_vect) | |
| void | BenchTimer::start () |
| Starts a measurement (the first one also measures the overhead). | |
| uint32_t | BenchTimer::stop () |
| The CPU cycles since start(), without those of start() and stop(). | |
Variables | |
| bool | BenchTimer::calibrated { false } |
| volatile uint16_t | BenchTimer::overflows { 0 } |
| uint32_t | BenchTimer::overhead { 0 } |
| uint8_t | BenchTimer::savedTimsk0 { 0 } |
Exact CPU cycle count of a benchmark loop, whatever its length.
Timer1 counts every CPU cycle; its overflow interrupt extends it to 32 bits, so a loop of up to 268 s can be timed. During the measurement, the millis() interrupt of Timer0 is paused and pending serial output has been sent: the only interrupt left is the Timer1 overflow, which happens a fixed number of times for a given loop. The count is then exact and the same from run to run, wherever the loop starts - unlike micros(), which advances in steps of 4 us and includes every millis() interrupt in between.
The cycles of start() and stop() themselves are measured once and subtracted.
Usage:
Definition in file bench_timer.h.
| ISR | ( | TIMER1_OVF_vect | ) |
Definition at line 90 of file bench_timer.h.