17
17
18
18
import io .netty .util .ResourceLeakDetector ;
19
19
import org .junit .Test ;
20
- import org .openjdk .jmh .output .OutputFormatType ;
20
+ import org .openjdk .jmh .annotations .Fork ;
21
+ import org .openjdk .jmh .annotations .Measurement ;
22
+ import org .openjdk .jmh .annotations .Scope ;
23
+ import org .openjdk .jmh .annotations .State ;
24
+ import org .openjdk .jmh .annotations .Warmup ;
21
25
import org .openjdk .jmh .output .results .ResultFormatType ;
22
26
import org .openjdk .jmh .runner .Runner ;
23
27
import org .openjdk .jmh .runner .options .ChainedOptionsBuilder ;
24
- import org .openjdk .jmh .runner .options .Options ;
25
28
import org .openjdk .jmh .runner .options .OptionsBuilder ;
26
29
27
30
import java .io .File ;
28
31
29
32
/**
30
33
* Base class for all JMH benchmarks.
31
34
*/
35
+ @ Warmup (iterations = AbstractMicrobenchmark .DEFAULT_WARMUP_ITERATIONS )
36
+ @ Measurement (iterations = AbstractMicrobenchmark .DEFAULT_MEASURE_ITERATIONS )
37
+ @ Fork (AbstractMicrobenchmark .DEFAULT_FORKS )
38
+ @ State (Scope .Thread )
32
39
public class AbstractMicrobenchmark {
33
40
34
- protected static final String WARMUP_ITERATIONS = "10" ;
35
- protected static final String MEASURE_ITERATIONS = "10" ;
36
- protected static final String NUM_FORKS = "2" ;
41
+ protected static final int DEFAULT_WARMUP_ITERATIONS = 10 ;
42
+ protected static final int DEFAULT_MEASURE_ITERATIONS = 1 ;
43
+ protected static final int DEFAULT_FORKS = 2 ;
37
44
38
45
protected static final String JVM_ARGS = "-server -dsa -da -ea:io.netty... -Xms768m" +
39
46
" -Xmx768m -XX:MaxDirectMemorySize=768m -XX:+AggressiveOpts -XX:+UseBiasedLocking" +
@@ -50,10 +57,19 @@ public void run() throws Exception {
50
57
51
58
ChainedOptionsBuilder runnerOptions = new OptionsBuilder ()
52
59
.include (".*" + className + ".*" )
53
- .jvmArgs (JVM_ARGS )
54
- .warmupIterations (getWarmupIterations ())
55
- .measurementIterations (getMeasureIterations ())
56
- .forks (getForks ());
60
+ .jvmArgs (JVM_ARGS );
61
+
62
+ if (getWarmupIterations () > 0 ) {
63
+ runnerOptions .warmupIterations (getWarmupIterations ());
64
+ }
65
+
66
+ if (getMeasureIterations () > 0 ) {
67
+ runnerOptions .measurementIterations (getMeasureIterations ());
68
+ }
69
+
70
+ if (getForks () > 0 ) {
71
+ runnerOptions .forks (getForks ());
72
+ }
57
73
58
74
if (getReportDir () != null ) {
59
75
String filePath = getReportDir () + className + ".json" ;
@@ -73,15 +89,15 @@ public void run() throws Exception {
73
89
}
74
90
75
91
protected int getWarmupIterations () {
76
- return Integer .parseInt (System .getProperty ("warmupIterations" , WARMUP_ITERATIONS ));
92
+ return Integer .parseInt (System .getProperty ("warmupIterations" , "-1" ));
77
93
}
78
94
79
95
protected int getMeasureIterations () {
80
- return Integer .parseInt (System .getProperty ("measureIterations" , MEASURE_ITERATIONS ));
96
+ return Integer .parseInt (System .getProperty ("measureIterations" , "-1" ));
81
97
}
82
98
83
99
protected int getForks () {
84
- return Integer .parseInt (System .getProperty ("forks" , NUM_FORKS ));
100
+ return Integer .parseInt (System .getProperty ("forks" , "-1" ));
85
101
}
86
102
87
103
protected String getReportDir () {
0 commit comments