Last active
January 1, 2016 02:59
-
-
Save jsleeio/8082345 to your computer and use it in GitHub Desktop.
arduino timing hackery
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 print_autonamed_value(p,x) do { p.print(#x " = "); p.println(x); } while (0) | |
#define print_named_value(p,n,x) do { p.print(n " = "); p.println(x); } while (0) | |
#define time_operation(p,op,sets,counts) do { \ | |
long mstart = millis(); \ | |
for (long set = 0; set < sets; set++) { \ | |
for (long count = 0; count < counts; count++) { \ | |
op; \ | |
} \ | |
} \ | |
long mend = millis(); \ | |
print_named_value(p,"sets", #sets); \ | |
print_named_value(p,"counts", #counts); \ | |
print_named_value(p,"op", #op); \ | |
print_named_value(p,"time taken", mend - mstart); \ | |
p.println(); \ | |
} while (0) | |
void setup() { | |
Serial.begin(9600); | |
delay(250); | |
} | |
void loop() { | |
float x = 1.23; | |
time_operation(Serial,x += (float) millis() / 1000.0,1000,1000); | |
print_named_value(Serial, "x", x); | |
delay(2500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment