changeset 1138:1ff6f05a9e8d

Internal cleanup of RunResult/BenchmarkResult.
author shade
date Fri, 20 Feb 2015 13:02:41 +0300
parents 4546bb1275b5
children 59dd39168ec6
files jmh-core/src/main/java/org/openjdk/jmh/results/BenchmarkResult.java jmh-core/src/main/java/org/openjdk/jmh/results/IterationResult.java jmh-core/src/main/java/org/openjdk/jmh/results/RunResult.java jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java jmh-core/src/test/java/org/openjdk/jmh/results/ResultAggregationTest.java jmh-core/src/test/java/org/openjdk/jmh/results/format/ResultFormatTest.java
diffstat 7 files changed, 20 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/results/BenchmarkResult.java	Thu Feb 19 21:57:19 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/results/BenchmarkResult.java	Fri Feb 20 13:02:41 2015 +0300
@@ -48,22 +48,10 @@
     private final Multimap<String, Result> benchmarkResults;
     private final BenchmarkParams params;
 
-    public BenchmarkResult(Collection<IterationResult> data) {
+    public BenchmarkResult(BenchmarkParams params, Collection<IterationResult> data) {
         this.benchmarkResults = new HashMultimap<String, Result>();
         this.iterationResults = data;
-
-        BenchmarkParams myParams = null;
-
-        for (IterationResult ir : data) {
-            BenchmarkParams params = ir.getBenchmarkParams();
-
-            if (myParams != null && !params.equals(myParams)) {
-                throw new IllegalStateException("Aggregating the iteration results from different benchmarks");
-            } else {
-                myParams = params;
-            }
-        }
-        this.params = myParams;
+        this.params = params;
     }
 
     public void addBenchmarkResult(Result r) {
--- a/jmh-core/src/main/java/org/openjdk/jmh/results/IterationResult.java	Thu Feb 19 21:57:19 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/results/IterationResult.java	Fri Feb 20 13:02:41 2015 +0300
@@ -102,10 +102,8 @@
     }
 
     public Result getPrimaryResult() {
-        Result next = primaryResults.iterator().next();
-
         @SuppressWarnings("unchecked")
-        Aggregator<Result> aggregator = next.getThreadAggregator();
+        Aggregator<Result> aggregator = primaryResults.get(0).getThreadAggregator();
         return aggregator.aggregate(primaryResults);
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/results/RunResult.java	Thu Feb 19 21:57:19 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/results/RunResult.java	Fri Feb 20 13:02:41 2015 +0300
@@ -43,22 +43,9 @@
     private final Collection<BenchmarkResult> benchmarkResults;
     private final BenchmarkParams params;
 
-    public RunResult(Collection<BenchmarkResult> data) {
+    public RunResult(BenchmarkParams params, Collection<BenchmarkResult> data) {
         this.benchmarkResults = data;
-
-        BenchmarkParams myParams = null;
-
-        for (BenchmarkResult br : data) {
-            BenchmarkParams params = br.getParams();
-
-            if (myParams != null && !params.equals(myParams)) {
-                throw new IllegalStateException("Aggregating the benchmark results from different benchmarks");
-            } else {
-                myParams = params;
-            }
-        }
-
-        this.params = myParams;
+        this.params = params;
     }
 
     public Collection<BenchmarkResult> getBenchmarkResults() {
@@ -90,7 +77,7 @@
                 results.add(ir);
             }
         }
-        BenchmarkResult result = new BenchmarkResult(results);
+        BenchmarkResult result = new BenchmarkResult(params, results);
         for (BenchmarkResult br : benchmarkResults) {
             for (String k : br.getBenchmarkResults().keys()) {
                 for (Result r : br.getBenchmarkResults().get(k)) {
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Thu Feb 19 21:57:19 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Fri Feb 20 13:02:41 2015 +0300
@@ -116,7 +116,7 @@
             doSingle(params, mode, acceptor);
 
             if (!res.isEmpty()) {
-                BenchmarkResult br = new BenchmarkResult(res);
+                BenchmarkResult br = new BenchmarkResult(params, res);
                 results.put(params, br);
                 out.endBenchmark(br);
             }
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Thu Feb 19 21:57:19 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Fri Feb 20 13:02:41 2015 +0300
@@ -556,7 +556,7 @@
     private SortedSet<RunResult> mergeRunResults(Multimap<BenchmarkParams, BenchmarkResult> results) {
         SortedSet<RunResult> result = new TreeSet<RunResult>(RunResult.DEFAULT_SORT_COMPARATOR);
         for (BenchmarkParams key : results.keys()) {
-            result.add(new RunResult(results.get(key)));
+            result.add(new RunResult(key, results.get(key)));
         }
         return result;
     }
@@ -657,7 +657,7 @@
                 if (!result.isEmpty()) {
                     long pid = server.getClientPid();
 
-                    BenchmarkResult br = new BenchmarkResult(result);
+                    BenchmarkResult br = new BenchmarkResult(params, result);
 
                     if (!profilersRev.isEmpty()) {
                         out.print("# Processing profiler results: ");
@@ -677,7 +677,7 @@
                 out.println("");
             }
 
-            out.endBenchmark(new RunResult(results.get(params)).getAggregatedResult());
+            out.endBenchmark(new RunResult(params, results.get(params)).getAggregatedResult());
 
         } catch (IOException e) {
             results.clear();
--- a/jmh-core/src/test/java/org/openjdk/jmh/results/ResultAggregationTest.java	Thu Feb 19 21:57:19 2015 +0300
+++ b/jmh-core/src/test/java/org/openjdk/jmh/results/ResultAggregationTest.java	Fri Feb 20 13:02:41 2015 +0300
@@ -47,7 +47,7 @@
         Assert.assertEquals(2, ir.getRawPrimaryResults().size());
         Assert.assertEquals(2, ir.getRawSecondaryResults().get("sec").size());
 
-        BenchmarkResult br = new BenchmarkResult(Arrays.asList(ir, ir));
+        BenchmarkResult br = new BenchmarkResult(null, Arrays.asList(ir, ir));
         br.addBenchmarkResult(new ThroughputResult(ResultRole.SECONDARY, "bench", 3000, 1, TimeUnit.NANOSECONDS));
         Assert.assertEquals(20000.0, br.getPrimaryResult().getScore());
         Assert.assertEquals(10000.0, br.getSecondaryResults().get("sec").getScore());
@@ -57,7 +57,7 @@
         Assert.assertEquals(1, br.getSecondaryResults().get("bench").getSampleCount());
         Assert.assertEquals(2, br.getIterationResults().size());
 
-        RunResult rr = new RunResult(Arrays.asList(br, br));
+        RunResult rr = new RunResult(null, Arrays.asList(br, br));
         Assert.assertEquals(20000.0, rr.getPrimaryResult().getScore());
         Assert.assertEquals(10000.0, rr.getSecondaryResults().get("sec").getScore());
         Assert.assertEquals(3000.0, rr.getSecondaryResults().get("bench").getScore());
@@ -81,7 +81,7 @@
         Assert.assertEquals(2, ir.getRawPrimaryResults().size());
         Assert.assertEquals(2, ir.getRawSecondaryResults().get("sec").size());
 
-        BenchmarkResult br = new BenchmarkResult(Arrays.asList(ir, ir));
+        BenchmarkResult br = new BenchmarkResult(null, Arrays.asList(ir, ir));
         br.addBenchmarkResult(new AverageTimeResult(ResultRole.SECONDARY, "bench", 1, 3000, TimeUnit.NANOSECONDS));
         Assert.assertEquals(10000.0, br.getPrimaryResult().getScore());
         Assert.assertEquals(5000.0, br.getSecondaryResults().get("sec").getScore());
@@ -91,7 +91,7 @@
         Assert.assertEquals(1, br.getSecondaryResults().get("bench").getSampleCount());
         Assert.assertEquals(2, br.getIterationResults().size());
 
-        RunResult rr = new RunResult(Arrays.asList(br, br));
+        RunResult rr = new RunResult(null, Arrays.asList(br, br));
         Assert.assertEquals(10000.0, rr.getPrimaryResult().getScore());
         Assert.assertEquals(5000.0, rr.getSecondaryResults().get("sec").getScore());
         Assert.assertEquals(3000.0, rr.getSecondaryResults().get("bench").getScore());
@@ -124,7 +124,7 @@
         Assert.assertEquals(2, ir.getPrimaryResult().getSampleCount());
         Assert.assertEquals(2, ir.getSecondaryResults().get("sec").getSampleCount());
 
-        BenchmarkResult br = new BenchmarkResult(Arrays.asList(ir, ir));
+        BenchmarkResult br = new BenchmarkResult(null, Arrays.asList(ir, ir));
         br.addBenchmarkResult(new SampleTimeResult(ResultRole.SECONDARY, "bench", sb3000, TimeUnit.NANOSECONDS));
         Assert.assertEquals(10000.0, br.getPrimaryResult().getScore());
         Assert.assertEquals(5000.0, br.getSecondaryResults().get("sec").getScore());
@@ -134,7 +134,7 @@
         Assert.assertEquals(1, br.getSecondaryResults().get("bench").getSampleCount());
         Assert.assertEquals(2, br.getIterationResults().size());
 
-        RunResult rr = new RunResult(Arrays.asList(br, br));
+        RunResult rr = new RunResult(null, Arrays.asList(br, br));
         Assert.assertEquals(10000.0, rr.getPrimaryResult().getScore());
         Assert.assertEquals(5000.0, rr.getSecondaryResults().get("sec").getScore());
         Assert.assertEquals(3000.0, rr.getSecondaryResults().get("bench").getScore());
@@ -158,7 +158,7 @@
         Assert.assertEquals(2, ir.getRawPrimaryResults().size());
         Assert.assertEquals(2, ir.getRawSecondaryResults().get("sec").size());
 
-        BenchmarkResult br = new BenchmarkResult(Arrays.asList(ir, ir));
+        BenchmarkResult br = new BenchmarkResult(null, Arrays.asList(ir, ir));
         br.addBenchmarkResult(new SingleShotResult(ResultRole.SECONDARY, "bench", 3000, TimeUnit.NANOSECONDS));
         Assert.assertEquals(10000.0, br.getPrimaryResult().getScore());
         Assert.assertEquals(5000.0, br.getSecondaryResults().get("sec").getScore());
@@ -168,7 +168,7 @@
         Assert.assertEquals(1, br.getSecondaryResults().get("bench").getSampleCount());
         Assert.assertEquals(2, br.getIterationResults().size());
 
-        RunResult rr = new RunResult(Arrays.asList(br, br));
+        RunResult rr = new RunResult(null, Arrays.asList(br, br));
         Assert.assertEquals(10000.0, rr.getPrimaryResult().getScore());
         Assert.assertEquals(5000.0, rr.getSecondaryResults().get("sec").getScore());
         Assert.assertEquals(3000.0, rr.getSecondaryResults().get("bench").getScore());
--- a/jmh-core/src/test/java/org/openjdk/jmh/results/format/ResultFormatTest.java	Thu Feb 19 21:57:19 2015 +0300
+++ b/jmh-core/src/test/java/org/openjdk/jmh/results/format/ResultFormatTest.java	Fri Feb 20 13:02:41 2015 +0300
@@ -95,9 +95,9 @@
                     res.addResult(new ThroughputResult(ResultRole.SECONDARY, "secondary2", r.nextInt(1000), 1000 * 1000, TimeUnit.MILLISECONDS));
                     iterResults.add(res);
                 }
-                benchmarkResults.add(new BenchmarkResult(iterResults));
+                benchmarkResults.add(new BenchmarkResult(params, iterResults));
             }
-            results.add(new RunResult(benchmarkResults));
+            results.add(new RunResult(params, benchmarkResults));
         }
         return results;
     }