Created
July 27, 2016 20:06
-
-
Save edgardleal/a0d969ac117604dad5272c47e2148dbc to your computer and use it in GitHub Desktop.
A simple static class to mark duration of execution in same part of your Java code.
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
| static class Benchmark { | |
| static HashMap<String, Double> points = new HashMap<String, Double>(); | |
| public static void start(final String label) { | |
| points.put(label, (double) System.nanoTime()); | |
| } | |
| public static void end(final String label) { | |
| points.put(label, System.nanoTime() - points.get(label)); | |
| } | |
| public static void print() { | |
| Set<Entry<String, Double>> set = points.entrySet(); | |
| Iterator<Entry<String, Double>> iterator = set.iterator(); | |
| while(iterator.hasNext()) { | |
| Entry<String, Double> entry = iterator.next(); | |
| System.out.printf("%10s - %5.2fms\n", entry.getKey(), (entry.getValue()/1000000D)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment