Skip to content

Instantly share code, notes, and snippets.

@edgardleal
Created July 27, 2016 20:06
Show Gist options
  • Select an option

  • Save edgardleal/a0d969ac117604dad5272c47e2148dbc to your computer and use it in GitHub Desktop.

Select an option

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.
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