Skip to content

Commit 9b2f4e3

Browse files
committed
Take care of the order of benchmarks and remove outliers
1 parent 4d2594e commit 9b2f4e3

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

  • msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/benchmark

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/benchmark/Benchmarker.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation;
2020

2121
import java.util.ArrayList;
22+
import java.util.Arrays;
2223
import java.util.List;
2324

2425
public class Benchmarker
@@ -58,32 +59,34 @@ public void run(int count, int warmupCount)
5859
throws Exception
5960
{
6061
List<Tuple<String, double[]>> benchmarksResults = new ArrayList<Tuple<String, double[]>>(benchmarkableList.size());
61-
6262
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+
}
6965

66+
for (int i = 0; i < count + warmupCount; i++) {
67+
for (int bi = 0; bi < benchmarkableList.size(); bi++) {
68+
Benchmarkable benchmark = benchmarkableList.get(bi);
7069
long currentTimeNanos = System.nanoTime();
7170
benchmark.run();
7271

7372
if (i >= warmupCount) {
74-
durations[i - warmupCount] = (System.nanoTime() - currentTimeNanos) / 1000000.0;
73+
benchmarksResults.get(bi).second[i - warmupCount] = (System.nanoTime() - currentTimeNanos) / 1000000.0;
7574
}
7675
}
77-
benchmarksResults.add(new Tuple<String, double[]>(benchmark.label, durations));
7876
}
7977

8078
for (Tuple<String, double[]> benchmarkResult : benchmarksResults) {
8179
printStat(benchmarkResult.first, benchmarkResult.second);
8280
}
8381
}
8482

85-
private void printStat(String label, double[] values)
83+
private void printStat(String label, double[] origValues)
8684
{
85+
double[] values = origValues;
86+
Arrays.sort(origValues);
87+
if (origValues.length > 2) {
88+
values = Arrays.copyOfRange(origValues, 1, origValues.length - 1);
89+
}
8790
StandardDeviation standardDeviation = new StandardDeviation();
8891
System.out.println(label + ":");
8992
System.out.println(String.format(" mean : %8.3f", StatUtils.mean(values)));

0 commit comments

Comments
 (0)