changeset 272:93cbcb0f4c8c

Cleanup BenchmarkParams.
author shade
date Mon, 25 Nov 2013 20:50:57 +0400
parents 5d7e2200fd17
children 195fb9b144cb
files jmh-core/src/main/java/org/openjdk/jmh/output/format/TextReportFormat.java jmh-core/src/main/java/org/openjdk/jmh/output/results/CSVResultFormat.java jmh-core/src/main/java/org/openjdk/jmh/output/results/JSONResultFormat.java jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/BenchmarkParams.java
diffstat 5 files changed, 99 insertions(+), 101 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/format/TextReportFormat.java	Mon Nov 25 20:43:49 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/format/TextReportFormat.java	Mon Nov 25 20:50:57 2013 +0400
@@ -62,7 +62,7 @@
         }
 
         out.println("# Warmup: " + mbParams.getWarmup().getCount() + " iterations, " + mbParams.getWarmup().getTime() + " each");
-        out.println("# Measurement: " + mbParams.getIteration().getCount() + " iterations, " + mbParams.getIteration().getTime() + " each");
+        out.println("# Measurement: " + mbParams.getMeasurement().getCount() + " iterations, " + mbParams.getMeasurement().getTime() + " each");
         out.println("# Threads: " + mbParams.getThreads() + " " + getThreadsString(mbParams.getThreads()) + (mbParams.shouldSynchIterations() ? ", will synchronize iterations" : ""));
         out.println("# Benchmark mode: " + name.getMode().longLabel());
         out.println("# Running: " + name.getUsername());
@@ -182,7 +182,7 @@
             RunResult res = runResults.get(key);
 
             int threads = res.getParams().getThreads();
-            TimeValue runTime = res.getParams().getIteration().getTime();
+            TimeValue runTime = res.getParams().getMeasurement().getTime();
 
             {
                 Statistics stats = res.getPrimaryResult().getStatistics();
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/results/CSVResultFormat.java	Mon Nov 25 20:43:49 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/results/CSVResultFormat.java	Mon Nov 25 20:50:57 2013 +0400
@@ -57,9 +57,9 @@
                 pw.print("\", ");
                 pw.print(runResult.getParams().getThreads());
                 pw.print(", ");
-                pw.print(runResult.getParams().getIteration().getCount());
+                pw.print(runResult.getParams().getMeasurement().getCount());
                 pw.print(", \"");
-                pw.print(runResult.getParams().getIteration().getTime());
+                pw.print(runResult.getParams().getMeasurement().getTime());
                 pw.print("\", ");
                 pw.print(runResult.getPrimaryResult().getStatistics().getMean());
                 pw.print(", ");
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/results/JSONResultFormat.java	Mon Nov 25 20:43:49 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/results/JSONResultFormat.java	Mon Nov 25 20:50:57 2013 +0400
@@ -66,8 +66,8 @@
                 pw.println("\"benchmark\" : \"" + br.getUsername() + "\",");
                 pw.println("\"mode\" : \"" + br.getMode().shortLabel() + "\",");
                 pw.println("\"threads\" : " + runResult.getParams().getThreads() + ",");
-                pw.println("\"iterations\" : " + runResult.getParams().getIteration().getCount() + ",");
-                pw.println("\"iterationTime\" : \"" + runResult.getParams().getIteration().getTime() + "\",");
+                pw.println("\"iterations\" : " + runResult.getParams().getMeasurement().getCount() + ",");
+                pw.println("\"iterationTime\" : \"" + runResult.getParams().getMeasurement().getTime() + "\",");
                 pw.println("\"primaryMetric\" : {");
                 pw.println("\"score\" : " + runResult.getPrimaryResult().getScore() + ",");
                 pw.println("\"scoreError\" : " + runResult.getPrimaryResult().getStatistics().getMeanErrorAt(0.999) + ",");
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Mon Nov 25 20:43:49 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Mon Nov 25 20:50:57 2013 +0400
@@ -96,13 +96,13 @@
             }
 
             out.iteration(handler.getBenchmark(), wp, i, IterationType.WARMUP);
-            boolean isLastIteration = (executionParams.getIteration().getCount() == 0);
+            boolean isLastIteration = (executionParams.getMeasurement().getCount() == 0);
             IterationResult iterData = handler.runIteration(wp, isLastIteration);
             out.iterationResult(handler.getBenchmark(), wp, i, IterationType.WARMUP, iterData);
         }
 
         // measurement
-        IterationParams mp = executionParams.getIteration();
+        IterationParams mp = executionParams.getMeasurement();
         for (int i = 1; i <= mp.getCount(); i++) {
             // will run system gc if we should
             if (runSystemGC()) {
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/BenchmarkParams.java	Mon Nov 25 20:43:49 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/BenchmarkParams.java	Mon Nov 25 20:50:57 2013 +0400
@@ -42,6 +42,69 @@
 
 public class BenchmarkParams implements Serializable {
 
+    private final boolean synchIterations;
+    private final int threads;
+    private final int[] threadGroups;
+    private final int forks;
+    private final int warmupForks;
+    private final IterationParams warmup;
+    private final IterationParams measurement;
+
+    private int decideForks(int optionForks, int benchForks) {
+        if (optionForks == -1) {
+            if (benchForks == -1) {
+                return Defaults.DEFAULT_FORK_TIMES;
+            } else {
+                return benchForks;
+            }
+        } else {
+            return optionForks;
+        }
+    }
+
+    private int decideWarmupForks(int optionWarmupForks, Fork forkAnnotation) {
+        if (optionWarmupForks == -1) {
+            return (forkAnnotation != null) ? forkAnnotation.warmups() : 0;
+        } else {
+            return optionWarmupForks;
+        }
+    }
+
+    /**
+     * Tests if the benchmark has the fork annotation
+     */
+    private int benchForks(BenchmarkRecord benchmark) {
+        Method m = MicroBenchmarkHandlers.findBenchmarkMethod(benchmark);
+        Fork fork = m.getAnnotation(Fork.class);
+        return (fork != null) ? fork.value() : -1;
+    }
+
+    public BenchmarkParams(Options options, BenchmarkRecord benchmark, boolean doWarmup, boolean doMeasurement) {
+        Class<?> clazz = ClassUtils.loadClass(benchmark.generatedClass());
+        Method method = MicroBenchmarkHandlers.findBenchmarkMethod(clazz, benchmark.generatedMethod());
+
+        this.threadGroups = decideThreadGroups(options.getThreadGroups(), benchmark.getThreadGroups());
+
+        int threads = getThreads(options, method);
+        if (threads == Threads.MAX) {
+            threads = Runtime.getRuntime().availableProcessors();
+        }
+        this.threads = Utils.roundUp(threads, Utils.sum(threadGroups));
+
+        this.synchIterations = getBoolean(options.getSynchIterations(), Defaults.SHOULD_SYNCH_ITERATIONS);
+
+        this.measurement = doMeasurement ?
+                getMeasurement(options, benchmark, method) :
+                new IterationParams(this, 0, TimeValue.NONE);
+
+        this.warmup = doWarmup ?
+                getWarmup(options, benchmark, method) :
+                new IterationParams(this, 0, TimeValue.NONE);
+
+        this.forks = decideForks(options.getForkCount(), benchForks(benchmark));
+        this.warmupForks = decideWarmupForks(options.getWarmupForkCount(), method.getAnnotation(Fork.class));
+    }
+
     private IterationParams getWarmup(Options options, BenchmarkRecord benchmark, Method method) {
         boolean isSingleShot = (benchmark.getMode() == Mode.SingleShotTime);
         Warmup warAnn = method.getAnnotation(Warmup.class);
@@ -93,87 +156,6 @@
         }
     }
 
-    private static int[] decideThreadGroups(int[] first, int[] second) {
-        if (first.length == 1 && first[0] == 1) {
-            return second;
-        } else {
-            return first;
-        }
-    }
-
-    private static int getThreads(Options options, Method method) {
-        Threads threadsAnn = method.getAnnotation(Threads.class);
-        return options.getThreads() > Integer.MIN_VALUE ?
-                options.getThreads() :
-                (threadsAnn != null ? threadsAnn.value() : Defaults.THREADS);
-    }
-
-    private final boolean synchIterations;
-    private final int threads;
-    private final int[] threadGroups;
-    private final int forks;
-    private final int warmupForks;
-    private final IterationParams warmup;
-    private final IterationParams iteration;
-
-    private int decideForks(int optionForks, int benchForks) {
-        if (optionForks == -1) {
-            if (benchForks == -1) {
-                return Defaults.DEFAULT_FORK_TIMES;
-            } else {
-                return benchForks;
-            }
-        } else {
-            return optionForks;
-        }
-    }
-
-    private int decideWarmupForks(int optionWarmupForks, Fork forkAnnotation) {
-        if (optionWarmupForks == -1) {
-            return (forkAnnotation != null) ? forkAnnotation.warmups() : 0;
-        } else {
-            return optionWarmupForks;
-        }
-    }
-
-    /**
-     * Tests if the benchmark has the fork annotation
-     */
-    private int benchForks(BenchmarkRecord benchmark) {
-        Method m = MicroBenchmarkHandlers.findBenchmarkMethod(benchmark);
-        Fork fork = m.getAnnotation(Fork.class);
-        return (fork != null) ? fork.value() : -1;
-    }
-
-    public BenchmarkParams(Options options, BenchmarkRecord benchmark, boolean doWarmup, boolean doMeasurement) {
-        Class<?> clazz = ClassUtils.loadClass(benchmark.generatedClass());
-        Method method = MicroBenchmarkHandlers.findBenchmarkMethod(clazz, benchmark.generatedMethod());
-
-        this.threadGroups = decideThreadGroups(options.getThreadGroups(), benchmark.getThreadGroups());
-
-        int threads = getThreads(options, method);
-        if (threads == Threads.MAX) {
-            threads = Runtime.getRuntime().availableProcessors();
-        }
-        threads = Utils.roundUp(threads, Utils.sum(threadGroups));
-        this.threads = threads;
-
-        this.synchIterations = getBoolean(options.getSynchIterations(), Defaults.SHOULD_SYNCH_ITERATIONS);
-
-        this.iteration = doMeasurement ?
-                getMeasurement(options, benchmark, method) :
-                new IterationParams(this, 0, TimeValue.NONE);
-
-        this.warmup = doWarmup ?
-                getWarmup(options, benchmark, method) :
-                new IterationParams(this, 0, TimeValue.NONE);
-
-        Fork forkAnnotation = method.getAnnotation(Fork.class);
-
-        this.forks = decideForks(options.getForkCount(), benchForks(benchmark));
-        this.warmupForks = decideWarmupForks(options.getWarmupForkCount(), forkAnnotation);
-    }
-
     public boolean shouldSynchIterations() {
         return synchIterations;
     }
@@ -182,8 +164,8 @@
         return warmup;
     }
 
-    public IterationParams getIteration() {
-        return iteration;
+    public IterationParams getMeasurement() {
+        return measurement;
     }
 
     public int getThreads() {
@@ -202,14 +184,6 @@
         return warmupForks;
     }
 
-    private static boolean getBoolean(Boolean value, boolean defaultValue) {
-        return value == null ? defaultValue : value;
-    }
-
-    private static int getInteger(int first, int second, int third) {
-        return first >= 0 ? first : (second >= 0 ? second : third);
-    }
-
     @Override
     public boolean equals(Object o) {
         if (this == o) return true;
@@ -221,7 +195,7 @@
         if (synchIterations != that.synchIterations) return false;
         if (threads != that.threads) return false;
         if (warmupForks != that.warmupForks) return false;
-        if (!iteration.equals(that.iteration)) return false;
+        if (!measurement.equals(that.measurement)) return false;
         if (!Arrays.equals(threadGroups, that.threadGroups)) return false;
         if (!warmup.equals(that.warmup)) return false;
 
@@ -236,7 +210,31 @@
         result = 31 * result + forks;
         result = 31 * result + warmupForks;
         result = 31 * result + warmup.hashCode();
-        result = 31 * result + iteration.hashCode();
+        result = 31 * result + measurement.hashCode();
         return result;
     }
+
+    private static int[] decideThreadGroups(int[] first, int[] second) {
+        if (first.length == 1 && first[0] == 1) {
+            return second;
+        } else {
+            return first;
+        }
+    }
+
+    private static int getThreads(Options options, Method method) {
+        Threads threadsAnn = method.getAnnotation(Threads.class);
+        return options.getThreads() > Integer.MIN_VALUE ?
+                options.getThreads() :
+                (threadsAnn != null ? threadsAnn.value() : Defaults.THREADS);
+    }
+
+    private static boolean getBoolean(Boolean value, boolean defaultValue) {
+        return value == null ? defaultValue : value;
+    }
+
+    private static int getInteger(int first, int second, int third) {
+        return first >= 0 ? first : (second >= 0 ? second : third);
+    }
+
 }