I need to determine how long an if statement was executed. I made a simple piece of code to simplify my case:
import org.joda.time.DateTime;
int a;
void setup() {
int a = 1;
}
void draw() {
if (a==1) {
System.out.println(" a is equal to 1");
}
else {
System.out.println(" a is not equal to 1");
}
}
In Processing, the draw method keeps on being executed forever. So it will constantly check if a is equal to 1. In my program, a's value is going to change dynamically based on Reactivision: if a particular element is detected, a will be equal to 1. If not, it will be equal to 0.
I want to know how long has the if statement been executed (to know how long the particular element will be detected).
If I use:
void draw() {
long startTime = System.nanoTime();
if (a==1) {
System.out.println(" a is equal to 1");
}
long estimatedTime = System.nanoTime() - startTime;
else {
System.out.println(" a is not equal to 1");
}
}
each time the draw method will be executed to check if a is equal to 1, it will reset startTime to the current time so it won't be able to add the time already elapsed.
I thought of using joda time, but is there a way to make it "record" how long the if statement was executed ?