Created
March 14, 2017 05:49
-
-
Save gilchris/8f24fe0a636720e5eea6d4ed862be66c to your computer and use it in GitHub Desktop.
Simple running time checker
This file contains hidden or 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
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