Skip to content

Instantly share code, notes, and snippets.

@gilchris
Created March 14, 2017 05:49
Show Gist options
  • Save gilchris/8f24fe0a636720e5eea6d4ed862be66c to your computer and use it in GitHub Desktop.
Save gilchris/8f24fe0a636720e5eea6d4ed862be66c to your computer and use it in GitHub Desktop.
Simple running time checker
import android.util.Log;
public class StopWatch {
private static String TAG = "StopWatch";
private static long baseTime;
private static long lastCheckTime;
private static long nowTime;
public static void start(String msg) {
baseTime = System.currentTimeMillis();
lastCheckTime = baseTime;
nowTime = baseTime;
log(msg);
}
public static void check(String msg) {
lastCheckTime = nowTime;
nowTime = System.currentTimeMillis();
log(msg);
}
public static void end(String msg) {
check(msg);
}
public static void reset() {
baseTime = 0;
lastCheckTime = 0;
nowTime = 0;
}
public static void log(String msg) {
Log.d(TAG, String.format("[%s] Total: %dms Last Check Point From: %dms", msg, (nowTime - baseTime), (nowTime - lastCheckTime)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment