How to measure the speed of an Arduino function?

I need to determine the speed at which the Arduino performs a specific function.

What is the best time for this? So far I have found something with a stopwatch class, but I am wondering if there is any own method for this.

+10
c ++ time stopwatch arduino
source share
2 answers

An easy way is to use the millis() or micros() function in the Arduino library. You will get a more accurate result with micros() .

For example:

 unsigned long start = micros(); // Call to your function myFunction(); // Compute the time it took unsigned long end = micros(); unsigned long delta = end - start; Serial.println(delta); 

Read the micros() documentation carefully: there is some time resolution information.

+16
source share

The least intrusive way is to set the port pins before calling the function and the subsequent low value. Place the oscilloscope on the port pin and measure for a long time.

It can also give you a good qualitative idea of ​​runtime variability by triggering on the rising edge and observing the jitter on the falling edge.

+9
source share

All Articles