Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Purpose

Gives you the execution time of your code in microseconds.

When to use

Whenever you want to know the time that just took the void loop()to be executed completely.

Where to use

In the void loop() part of your .ino file.

Note

Since knowing the code execution time is rarely relevant in a match setting, this function will be rarely used, if ever, in the final version of your code. It is mostly used for debugging purposes.

Note

This function requires the use of the following functions at some point of your .ino file in order to work properly:

Returns

Returns the elapsed time, in microseconds (4μs resolution), between the last two calls of the CrcLib::Update() function as an unsigned int type.

Main prototype and parameters

static unsigned int Crc:: CrcLib::GetDeltaTimeMicros()

The following parameters must be passed to the function for it to work properly:

  • No parameters needed.

Overloads

This function does not have any overloads. It can only be used as described by the main prototype.

Examples

Expand
title#1: We want to show the code execution time on the Arduino IDE Serial Monitor.
Code Block
languagecpp
#include <CrcLib.h>

using namespace Crc;

void setup() {
    CrcLib::Initialize();

    //Open the communication with the Serial monitor at a 2000000 baud rate
    Serial.begin(2000000);
    
    /* 
    The rest of your setup code
    ...
     */
}
void loop() {
    CrcLib::Update();

    //Print on the Serial monitor the elaspsed time betwwen the last two calls of CrcLib::Update()
    Serial.print("The code execution time is ");
    Serial.print(CrcLib::GetDeltaTimeMicros());
    Serial.println(" μs.");
    
    /* 
    The rest of your looping code
    ...
    */
}

More on this function

Info
What’s the difference between the Serial.print() and Serial.prinln() native Arduino functions used in the example ?

This page is a good starting point to learn about the New Line character.

Info
What is a time resolution?

The time resolution is the smallest time interval that can be measured. Here, the time returned by the function will always be a multiple of 4μs

Articles liés
Filter by label (Content by label)
spacescom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@831
sorttitle
typepage
excerptTyperich content
labelskb-how-to-article
cqllabel = "ar-crclib_fonctfunct_utilitaires"labelskb-how-to-articleutilities"