简体   繁体   English

JMH启动脚本->例如,设置Iterations(5)

[英]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.

相关问题 启动并获取.jar的输出(例如Minecraft Bukkit .jar) - Start and get output of a .jar (E.g. Minecraft Bukkit .jar) 使用Java for Android平台评估脚本(例如Python) - Evaluate a script (e.g. Python) in Java for Android platform 使用javax.script或Rhino在带有浏览器上下文(例如envjs)的Java中运行javascript? - Using javax.script or Rhino to run javascript in Java with browser context (e.g. envjs)? 如何像在后台该目录中一样执行脚本(例如mvnw)? - How to execute a script (e.g. mvnw) as if you were in that directory in the background? Java - 如何根据自定义比较最好地执行类似集合的操作(例如retainAll) - Java - how best to perform set-like operations (e.g. retainAll) based on custom comparison 如何从 LinkedHashMap 集合中获取双数组的键集(例如数组 [double]) - How do I get a keyset of double arrays (e.g. array[double]) from a LinkedHashMap set 每当 JFrame 聚焦时(例如通过单击或使用 Alt+Tab),我如何设置聚焦组件? - How can I set a Component focused whenever the JFrame is focused (e.g. by clicking or with Alt+Tab)? IDE中的智能注释(例如Netbeans) - Smart commenting in an IDE (e.g. Netbeans) 有没有办法在Tomcat中以编程方式将SSL设置为必需(例如,不通过web.xml)? - Is there a way to programmatically set SSL as mandatory in Tomcat (e.g. not via web.xml)? 如何设置带有输入长度和范围的DocumentFilter? 例如1-3或10-80 - How to set DocumentFilter with input length and range? e.g. 1-3 or 10-80
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM