Last active
January 17, 2016 02:01
-
-
Save autovalue/be0016d0654c234ee6ea to your computer and use it in GitHub Desktop.
Android Java equivalent of JavaScript's console.time function
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; | |
import java.util.HashMap; | |
public class Timer { | |
private static HashMap<String, Long> measurements = new HashMap<>(); | |
private Timer(){} | |
public static void start(String benchmark){ | |
measurements.put(benchmark, System.currentTimeMillis()); | |
} | |
public static long end(String benchmark) { | |
if(measurements.containsKey(benchmark)) { | |
long startTime = measurements.remove(benchmark); | |
long elapsedTime = System.currentTimeMillis() - startTime; | |
Log.d("MethodTimer", "[" + benchmark + "] Elapsed time: " + elapsedTime + "ms."); | |
return elapsedTime; | |
} | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment