|
19 | 19 | import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; |
20 | 20 |
|
21 | 21 | import java.util.ArrayList; |
| 22 | +import java.util.Arrays; |
22 | 23 | import java.util.List; |
23 | 24 |
|
24 | 25 | public class Benchmarker |
@@ -58,32 +59,34 @@ public void run(int count, int warmupCount) |
58 | 59 | throws Exception |
59 | 60 | { |
60 | 61 | List<Tuple<String, double[]>> benchmarksResults = new ArrayList<Tuple<String, double[]>>(benchmarkableList.size()); |
61 | | - |
62 | 62 | for (Benchmarkable benchmark : benchmarkableList) { |
63 | | - double[] durations = new double[count]; |
64 | | - |
65 | | - for (int i = 0; i < count + warmupCount; i++) { |
66 | | - if (i >= warmupCount) { |
67 | | - System.gc(); |
68 | | - } |
| 63 | + benchmarksResults.add(new Tuple<String, double[]>(benchmark.label, new double[count])); |
| 64 | + } |
69 | 65 |
|
| 66 | + for (int i = 0; i < count + warmupCount; i++) { |
| 67 | + for (int bi = 0; bi < benchmarkableList.size(); bi++) { |
| 68 | + Benchmarkable benchmark = benchmarkableList.get(bi); |
70 | 69 | long currentTimeNanos = System.nanoTime(); |
71 | 70 | benchmark.run(); |
72 | 71 |
|
73 | 72 | if (i >= warmupCount) { |
74 | | - durations[i - warmupCount] = (System.nanoTime() - currentTimeNanos) / 1000000.0; |
| 73 | + benchmarksResults.get(bi).second[i - warmupCount] = (System.nanoTime() - currentTimeNanos) / 1000000.0; |
75 | 74 | } |
76 | 75 | } |
77 | | - benchmarksResults.add(new Tuple<String, double[]>(benchmark.label, durations)); |
78 | 76 | } |
79 | 77 |
|
80 | 78 | for (Tuple<String, double[]> benchmarkResult : benchmarksResults) { |
81 | 79 | printStat(benchmarkResult.first, benchmarkResult.second); |
82 | 80 | } |
83 | 81 | } |
84 | 82 |
|
85 | | - private void printStat(String label, double[] values) |
| 83 | + private void printStat(String label, double[] origValues) |
86 | 84 | { |
| 85 | + double[] values = origValues; |
| 86 | + Arrays.sort(origValues); |
| 87 | + if (origValues.length > 2) { |
| 88 | + values = Arrays.copyOfRange(origValues, 1, origValues.length - 1); |
| 89 | + } |
87 | 90 | StandardDeviation standardDeviation = new StandardDeviation(); |
88 | 91 | System.out.println(label + ":"); |
89 | 92 | System.out.println(String.format(" mean : %8.3f", StatUtils.mean(values))); |
|
0 commit comments