java/src/main/java/cz/cvut/fit/swing/calipel/core/BenchmarkInstance.java
changeset 254 e7f75a252b17
child 256 00902ea305e4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/java/src/main/java/cz/cvut/fit/swing/calipel/core/BenchmarkInstance.java	Wed Nov 05 21:15:34 2014 +0100
@@ -0,0 +1,35 @@
+package cz.cvut.fit.swing.calipel.core;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class BenchmarkInstance {
+
+    private Object benchmarkImplementation;
+    private String selector;
+
+    public BenchmarkInstance(Object benchmarkImplementation, String selector) {
+        this.benchmarkImplementation = benchmarkImplementation;
+        this.selector = selector;
+    }
+
+    public Long timeIt() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+        Method measuredMethod = benchmarkImplementation.getClass().getDeclaredMethod(selector);
+
+        Long start = System.currentTimeMillis();
+        measuredMethod.invoke(benchmarkImplementation);
+        Long end = System.currentTimeMillis();
+
+        return end - start;
+    }
+
+    public Map toMap() {
+        Map map = new LinkedHashMap();
+        map.put("class", benchmarkImplementation.getClass().getSimpleName());
+        map.put("selector", selector);
+
+        return map;
+    }
+}