|
|
@@ -8,93 +8,48 @@ package net.ranides.assira;
|
|
|
|
|
|
import com.google.caliper.SimpleBenchmark;
|
|
|
import java.io.PrintStream;
|
|
|
-import java.lang.reflect.Field;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.TreeMap;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
+import net.ranides.assira.BenchmarkRunner.ParamsField;
|
|
|
import net.ranides.assira.collection.Grid;
|
|
|
-import net.ranides.assira.reflection.ReflectUtils;
|
|
|
import net.ranides.assira.text.Strings;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @author Ranides Atterwim <ranides@gmail.com>
|
|
|
*/
|
|
|
-public final class BenchmarkFormatter {
|
|
|
+public final class BenchmarkReport {
|
|
|
|
|
|
private final Map<String, Grid<?>> params = new HashMap<>();
|
|
|
|
|
|
-
|
|
|
- public static List<Integer> getParams(Class<?> clazz) {
|
|
|
- ParamsField params = getParamsField(clazz);
|
|
|
- if(null == params) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- return params.value.column("param", Integer.class);
|
|
|
+ public static void print(PrintStream out, Class<?> clazz, String data) {
|
|
|
+ print(out, Arrays.<Class<?>>asList(clazz), data);
|
|
|
}
|
|
|
|
|
|
- private static ParamsField getParamsField(Class<?> clazz) {
|
|
|
- for(Field field : clazz.getDeclaredFields()) {
|
|
|
- ReflectUtils.access(field);
|
|
|
- BenchmarkRunner.ParamGrid info = field.getAnnotation(BenchmarkRunner.ParamGrid.class);
|
|
|
- if( null != info) {
|
|
|
- try {
|
|
|
- return new ParamsField(info.value(), (Grid<?>)field.get(null));
|
|
|
- } catch(ReflectiveOperationException cause) {
|
|
|
- throw new IllegalArgumentException(cause);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- private static class ParamsField {
|
|
|
- public final String[] keys;
|
|
|
- public final Grid<?> value;
|
|
|
-
|
|
|
- public ParamsField(String[] keys, Grid<?> value) {
|
|
|
- this.keys = keys;
|
|
|
- this.value = value;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static void report(List<Class<?>> list, String data) {
|
|
|
- BenchmarkFormatter formatter = new BenchmarkFormatter();
|
|
|
+ public static void print(PrintStream out, List<Class<?>> list, String data) {
|
|
|
+ BenchmarkReport formatter = new BenchmarkReport();
|
|
|
for(Class<?> clazz : list ) {
|
|
|
- if( SimpleBenchmark.class.isAssignableFrom(clazz) ) {
|
|
|
- formatter.putParams(clazz);
|
|
|
- }
|
|
|
- }
|
|
|
- formatter.print(data);
|
|
|
- }
|
|
|
-
|
|
|
- public static void report(Class<?> clazz, String data) {
|
|
|
- BenchmarkFormatter formatter = new BenchmarkFormatter();
|
|
|
- if( SimpleBenchmark.class.isAssignableFrom(clazz) ) {
|
|
|
formatter.putParams(clazz);
|
|
|
}
|
|
|
- formatter.print(data);
|
|
|
+ formatter.format(System.out, data);
|
|
|
}
|
|
|
|
|
|
private void putParams(Class<?> clazz) {
|
|
|
- ParamsField field = getParamsField(clazz);
|
|
|
- if(null == field) {
|
|
|
+ ParamsField field = new ParamsField(clazz);
|
|
|
+ if(!field.exists()) {
|
|
|
return;
|
|
|
}
|
|
|
- for(String key : field.keys) {
|
|
|
- params.put(key, field.value);
|
|
|
+ for(String key : field.keys()) {
|
|
|
+ params.put(key, field.value());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void print(String input) {
|
|
|
- format(System.out, input);
|
|
|
- }
|
|
|
-
|
|
|
private void format(PrintStream out, String input) {
|
|
|
Pattern RE_BENCHMARK = Pattern.compile("\\{vm=(.+?), trial=(.+?), benchmark=(.+?)(?:, param=(.+?))?\\} ([0-9,]+) ns; \\?=([0-9,]+) ns @ ([0-9]+) trials");
|
|
|
|