[英]JMH start script -> e.g. set Iterations(5)
When I start my Benchmark I will only have 5 warmupInterations, 5 measurementIterations and only 1 fork. 当启动我的基准测试时,我将只有5个warmupInterations,5个measurementIterations和只有1个fork。 I don't want to use the commandline options !
我不想使用命令行选项!
**my test code in Eclipse:**
package org.sample;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
public class MyBenchmark {
@Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.SECONDS)
public String[] testMethod() {
return "1,2,3,4,5,6,7,8,9,10".split(",");
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(MyBenchmark.class.getSimpleName())
.warmupIterations(5)
.measurementIterations(5)
.forks(1)
.build();
new Runner(opt).run();
}
}
Then I say 然后我说
mvn clean install
java -jar benchmark.jar
And I get the same ouput as always (no changed iterations or fork !!) 而且我得到的输出与往常一样(没有更改迭代或派生!!)
C:\Users\SPARK\Desktop\workspace\jmhBenchmark\target>java -jar benchmarks.jar
# JMH 1.11.3 (released 68 days ago)
# VM version: JDK 1.8.0_74, VM 25.74-b02
# VM invoker: C:\Program Files\Java\jre1.8.0_74\bin\java.exe
# VM options: <none>
# Warmup: 20 iterations, 1 s each
# Measurement: 20 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: org.sample.MyBenchmark.testMethod
# Run progress: 0,00% complete, ETA 00:06:40
# Fork: 1 of 10
# Warmup Iteration 1: 2108087,328 ops/s
# Warmup Iteration 2: 2435219,249 ops/s
# Warmup Iteration 3: 2589289,173 ops/s
# Warmup Iteration 4: 2606293,767 ops/s
# Warmup Iteration 5: 2548095,405 ops/s
# Warmup Iteration 6: 2594874,969 ops/s
# Warmup Iteration 7: 2583629,760 ops/s
# Warmup Iteration 8: 2579041,971 ops/s
# Warmup Iteration 9: 2580402,155 ops/s
# Warmup Iteration 10: 2546640,733 ops/s
# Warmup Iteration 11: 2580002,548 ops/s
# Warmup Iteration 12:
What I am doing wrong ?? 我做错了什么??
Thanks a lot for reading 非常感谢您的阅读
By executing java -jar benchmark.jar
the tests are executed using the default JMH settings. 通过执行
java -jar benchmark.jar
,将使用默认的JMH设置执行测试。
If you want to run the test using the settings specified by your OptionsBuilder
. 如果要使用
OptionsBuilder
指定的设置运行测试。 You have to run it as java -cp benchmark.jar org.sample.MyBenchmark
. 您必须将其作为
java -cp benchmark.jar org.sample.MyBenchmark
。
Find a complete example below. 在下面找到完整的示例。
mvn archetype:generate \
-DarchetypeGroupId=org.openjdk.jmh \
-DarchetypeArtifactId=jmh-java-benchmark-archetype \
-DgroupId=org.sample \
-DartifactId=jmh-example \
-Dversion=0.0.1 \
-DinteractiveMode=false
Replace the file src/main/java/org/sample/MyBenchmark.java
with your source. 将文件
src/main/java/org/sample/MyBenchmark.java
为您的源。
executing java -jar target/benchamrks.jar
use following settings 执行
java -jar target/benchamrks.jar
使用以下设置
# VM options: <none>
# Warmup: 20 iterations, 1 s each
# Measurement: 20 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: org.sample.MyBenchmark.testMethod
...
# Fork: 1 of 10
executing java -cp target/benchmarks.jar org.sample.MyBenchmark
use following settings 执行
java -cp target/benchmarks.jar org.sample.MyBenchmark
使用以下设置
# VM options: <none>
# Warmup: 5 iterations, 1 s each
# Measurement: 5 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: org.sample.MyBenchmark.testMethod
...
# Fork: 1 of 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.