changeset 197:a06bc28a0a73

@Warmup/@Measurement annotations misbehave when not supplied with the exact time.
author shade
date Tue, 08 Oct 2013 17:08:09 +0400
parents 78886630f76c
children 16583c0781de
files jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/BenchmarkParams.java jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/TimeValue.java
diffstat 2 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/BenchmarkParams.java	Mon Oct 07 14:50:40 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/BenchmarkParams.java	Tue Oct 08 17:08:09 2013 +0400
@@ -71,10 +71,10 @@
         } else {
             TimeValue timeValue = options.getWarmupTime();
             if (timeValue == null || timeValue.getTime() == -1) {
-                if (warAnn != null) {
+                if (warAnn == null || warAnn.time() == -1) {
+                    timeValue = Defaults.WARMUP_TIME;
+                } else {
                     timeValue = new TimeValue(warAnn.time(), warAnn.timeUnit());
-                } else {
-                    timeValue = Defaults.WARMUP_TIME;
                 }
             }
             return new IterationParams(getInteger(options.getWarmupIterations(), iters, Defaults.WARMUP_ITERATION_COUNT), timeValue, threads);
@@ -94,10 +94,10 @@
         } else {
             TimeValue timeValue = options.getRuntime();
             if (timeValue == null || timeValue.getTime() == -1) {
-                if (meAnn != null) {
+                if (meAnn == null || meAnn.time() == -1) {
+                    timeValue = Defaults.ITERATION_TIME;
+                } else {
                     timeValue = new TimeValue(meAnn.time(), meAnn.timeUnit());
-                } else {
-                    timeValue = Defaults.ITERATION_TIME;
                 }
             }
             return new IterationParams(
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/TimeValue.java	Mon Oct 07 14:50:40 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/TimeValue.java	Tue Oct 08 17:08:09 2013 +0400
@@ -70,6 +70,9 @@
     private final TimeUnit timeUnit;
 
     public TimeValue(long time, TimeUnit timeUnit) {
+        if (time < 0) {
+            throw new IllegalArgumentException("Time should be greater or equal to zero: " + time);
+        }
         this.time = time;
         this.timeUnit = timeUnit;
     }