Skip to content

Commit 930837f

Browse files
committed
give benchmarks a name
1 parent 1059f08 commit 930837f

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

  • common-tools/clas-utils/src/main/java/org/jlab/utils/benchmark

‎common-tools/clas-utils/src/main/java/org/jlab/utils/benchmark/Benchmark.java‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@
1818
*/
1919
public class Benchmark implements Comparator<String> {
2020

21-
private static final Benchmark benchmarkInstance = new Benchmark();
21+
String name;
22+
private static final Benchmark benchmarkInstance = new Benchmark("");
2223
private Map<String,BenchmarkMultiTimer> timerStore = new LinkedHashMap<>();
2324
private Timer updateTimer = null;
2425
private final ArrayList<String> specials = new ArrayList<>();
2526

26-
public Benchmark() {}
27+
public Benchmark(String name) {
28+
this.name = name;
29+
}
2730

28-
public Benchmark(String[] specials) {
31+
public Benchmark(String name, String[] specials) {
32+
this.name = name;
2933
this.specials.addAll(Arrays.asList(specials));
3034
}
3135

@@ -90,12 +94,12 @@ public String toString(){
9094
int len = timers.iterator().next().toString().length();
9195
char[] asterix = new char[len+8];
9296
Arrays.fill(asterix,'*');
93-
String margins = new String(asterix);
97+
String margins = new String(asterix) + "\n";
9498
s.append(margins);
95-
s.append("\n");
96-
s.append("* Benchmark Results \n");
99+
s.append("* ");
100+
s.append(name);
101+
s.append(" Benchmarks\n");
97102
s.append(margins);
98-
s.append("\n");
99103
for (BenchmarkTimer b : timers) {
100104
s.append("* ");
101105
s.append(b);
@@ -107,7 +111,6 @@ public String toString(){
107111
timers.stream().mapToDouble(x -> x.getSeconds()).sum(),
108112
timers.stream().mapToDouble(x -> x.getMillisecondsPerCall()).sum()));
109113
s.append(margins);
110-
s.append("\n");
111114
}
112115
return s.toString();
113116
}

0 commit comments

Comments
 (0)