StepTimer keeps track of how long it takes for something to execute. For example:
StepTimer stepTimer = new StepTimer("MATH");
stepTimer.start();
double result = doComplexMathCalculation(1, 2, 3); //replace this with your actual code.
stepTimer.log("Complex math calculation");
The output in the Android monitor would be:
01-02 03:04:05.678 901-234/? I/MATH: TIME: Complex math calculation: 567 ms
Here is an example from the image processing code:
stepTimer.start();
//save the raw camera image for logging
ImageUtil.saveImage(TAG, rgbaFrame, Imgproc.COLOR_RGBA2BGR, "00_camera", startTime);
stepTimer.log("save 00");
package ftc.evlib.util;
import android.util.Log;
/**
* This file was made by the electronVolts, FTC team 7393
* Date Created: 8/26/16
*
* Records and logs the time it takes to complete a certain step in an algorithm
*/
public class StepTimer {
private final String tag;
private long timer;
/**
* @param tag the tag to give to the android logging
* You can search for the tag in the logs to find messages generated by your code
*/
public StepTimer(String tag) {
this.tag = tag;
start();
}
/**
* Start a step
*/
public void start() {
timer = System.nanoTime();
}
/**
* Log the name of the step and the time since it started
*
* @param message the name of the step
*/
public void log(String message) {
Log.i(tag, "TIME: " + message + ": " + String.valueOf(get()) + " ms");
}
/**
* @return the time since the step started
*/
public double get() {
return (System.nanoTime() - timer) / 1000000.0;
}
}