Last active
January 23, 2021 12:46
-
-
Save jfjlaros/fc25862ccdeb01fd972b5a42068e5cee to your computer and use it in GitHub Desktop.
Snippet for timing analysis.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define SLOTS 100 | |
unsigned long _last[SLOTS]; | |
size_t _index = 0; | |
void set(void) { | |
_last[_index] = millis(); | |
_index++; | |
} | |
void delta(char* label) { | |
_index--; | |
char buf[80]; | |
sprintf(buf, "%04i %s", millis() - _last[_index], label); | |
Serial.println(buf); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern void set(void); | |
extern void delta(char*); | |
void some_function(void) { | |
set(); // Record current time in slot 0. | |
set(); // Record current time in slot 1. | |
some_call(); | |
delta("some_call"); // Write the duration of `some_call()` to serial, free slot 1. | |
set(); // Record current time in slot 1. | |
some_other_call(); | |
delta("some_other_call"); // Write the duration of `some_other_call()` to serial, free slot 1. | |
delta("total"); // Write the duration of the entire function to serial, free slot 0. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0247 some_call | |
0527 some_other_call | |
0774 total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment