Skip to content

Commit 1059f08

Browse files
authored
add benchmark printout ordering feature (#1446)
* add option to reorder some benchmarks * rename new method
1 parent cbb41ba commit 1059f08

1 file changed

Lines changed: 31 additions & 4 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: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package org.jlab.utils.benchmark;
22

33
import java.util.Arrays;
4+
import java.util.ArrayList;
45
import java.util.Collection;
6+
import java.util.Collections;
7+
import java.util.Comparator;
58
import java.util.LinkedHashMap;
9+
import java.util.List;
610
import java.util.Map;
711
import java.util.Timer;
812
import java.util.TimerTask;
@@ -12,14 +16,19 @@
1216
*
1317
* @author gavalian
1418
*/
15-
public class Benchmark {
16-
19+
public class Benchmark implements Comparator<String> {
20+
1721
private static final Benchmark benchmarkInstance = new Benchmark();
18-
private final Map<String,BenchmarkMultiTimer> timerStore = new LinkedHashMap<>();
22+
private Map<String,BenchmarkMultiTimer> timerStore = new LinkedHashMap<>();
1923
private Timer updateTimer = null;
24+
private final ArrayList<String> specials = new ArrayList<>();
2025

2126
public Benchmark() {}
22-
27+
28+
public Benchmark(String[] specials) {
29+
this.specials.addAll(Arrays.asList(specials));
30+
}
31+
2332
public static Benchmark getInstance(){
2433
return benchmarkInstance;
2534
}
@@ -111,4 +120,22 @@ public String[] toCSV() {
111120
};
112121
}
113122

123+
public void sortByName() {
124+
List<String> keys = new ArrayList<>(timerStore.keySet());
125+
Collections.sort(keys, this);
126+
Map<String,BenchmarkMultiTimer> timers = new LinkedHashMap<>();
127+
for (String s : keys)
128+
timers.put(s, timerStore.get(s));
129+
timerStore = timers;
130+
}
131+
132+
@Override
133+
public int compare(String s1, String s2) {
134+
if (specials.contains(s1)) {
135+
return specials.contains(s2) ? s1.compareTo(s2) : -1;
136+
} else {
137+
return specials.contains(s2) ? 1 : s1.compareTo(s2);
138+
}
139+
}
140+
114141
}

0 commit comments

Comments
 (0)