- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在尝试使用 JMH 中的超时时,我发现实际上没有任何超时会导致任何中断。我可以将问题简化为以下几行:
package main.java;
import org.openjdk.jmh.Main;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.RunnerException;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class TimeoutBenchmark {
public static void main(String... args) throws IOException, RunnerException {
Main.main(args);
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@Warmup(iterations = 0)
@Timeout(time = 10, timeUnit = TimeUnit.SECONDS)
public long benchmark() throws InterruptedException {
Thread.sleep(20000);
return 0;
}
}
由于 Thread.sleep
处理中断,我希望每次迭代运行 10 秒,而不是 20 秒。然而,事实并非如此:
# JMH version: 1.20
# VM version: JDK 1.8.0_144, VM 25.144-b01
# VM invoker: C:\Program Files\Java\jdk1.8.0_144\jre\bin\java.exe
# VM options: -Dfile.encoding=UTF-8
# Warmup: <none>
# Measurement: 20 iterations, 1 s each
# Timeout: 10 s per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: main.java.TimeoutBenchmark.benchmark
# Run progress: 0,00% complete, ETA 00:03:20
# Fork: 1 of 10
Iteration 1: 20,004 s/op
Iteration 2: 20,009 s/op
Iteration 3: 20,009 s/op
Iteration 4: 20,014 s/op
Iteration 5: 20,003 s/op
Iteration 6: 20,003 s/op
Iteration 7: 20,003 s/op
这是为什么呢?如何更改此代码,使每次迭代实际上在 10 秒后中断?
最佳答案
在BenchmarkHandler
中有处理超时的代码注释
// now we communicate all worker threads should stop
control.announceDone();
// wait for all workers to transit to teardown
control.awaitWarmdownReady();
// Wait for the result, handling timeouts
while (completed.size() < numThreads) {
所以基本上这个 Timeout 仅适用于 teardown
阶段。
但是我认为应该使用此信息修改此注释的 javadoc。
拆解说明如下:http://java-performance.info/jmh/
此邮件也很有用:http://mail.openjdk.java.net/pipermail/jmh-dev/2015-May/001912.html
关于java - JMH 超时不中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50003967/
我在网上找不到关于 here 的任何信息,谁能告诉我 ops/us, Cnt, Score, Error 是什么意思。 最佳答案 ops/us - 每微秒的操作(基准方法执行) Cnt - 试验总数(
我在网上找不到关于 here 的任何信息,谁能告诉我 ops/us, Cnt, Score, Error 是什么意思。 最佳答案 ops/us - 每微秒的操作(基准方法执行) Cnt - 试验总数(
在我的 jmh 课上,我正在使用 @BenchmarkMode(Mode.SampleTime) @Measurement(iterations = 10) @Threads(value = 10)
我已经将其视为微基准测试中的潜在陷阱之一。如果您指定@Measurement(或@Warmup)将运行固定的时间量,这意味着,当比较不同的运行(例如,不同的平台、不同版本的 VM 等)时,您将获得更少
想开始做我从现在开始写的方法的基准测试,有很长一段时间的动力,终于决定从昨天开始这样做。但我对我的设置过程感到震惊。 我已经正确安装了 JMH 插件。 所有导入工作正常。 甚至我的 POM 也没有显示
我正在使用 JMH,但发现有些难以理解:我有一种方法用 @Benchmark 注释。我设置了 measurementIterations(3) .该方法被调用了 3 次,但在每次迭代调用中,该函数运行
假设我有一个带有两个参数的 JMH 测试: @Param( { "1", "2", 4", "8", "16" } ) int param1; @Param( { "1", "2", 4", "8",
我正在使用tutorial学习JMH基准测试。 我注意到here中的功能benchMurmur3_128有2个与预热相关的东西。 因此,我对Fork注释中的热身属性和带有迭代属性的Warmup注释之间
我不明白 JMH 结果中的 score 属性?我也没有在网上找到任何关于它的信息。 谁能告诉我,它是关于什么的?据我所知,高分比低分好,但这究竟是什么意思,它是如何计算的? 最佳答案 JMH 支持以下
官方资源 官方Github样例 应用场景 对要使用的数据结构不确定,不知道谁的性能更好 对历史方法代码重构,要评判改造之后的性能提升多少 ( 我要做的场景 )
我用 JMH 测试我的程序性能。并且无法配置堆大小。我想知道为什么它不起作用。 问题: 为什么 JMH 不接受堆大小配置? JMH 是否在没有 jvmArgs 方法的情况下吸收 idea 堆大小设置?
我正在使用 JMH 对 DOM 解析器进行基准测试。我得到了非常奇怪的结果,因为第一次迭代实际上比后面的迭代运行得更快 谁能解释为什么会发生这种情况?另外,百分位数和所有数字是什么意思,为什么它在第三
我正在对 Spring Boot 应用程序启动时间进行基准测试。完整的项目是here ,这是 WIP,但相关类如下。 抽象基本状态: public abstract class BootAbstrac
我有:这样的方法: @GenerateMicroBenchmark public static void calculateArraySummary(String[] args) { // c
我读到了JMH并尝试了提供的示例。 我想做的是测量以下场景的统计数据, [ 1] client order -> [2] server -> [3] start processing the orde
我正在玩 Math.max 看看它是否受到分支预测的影响(不,至少在 x64 的 JDK 上不是,有一个 cmovl),如果按位实现可以与默认实现竞争。所有测试如下所示: @Threads(4) @S
我在 JMH 中看到一个常见问题 ConstantFold ,但是如果我有逆问题怎么办?我需要静态最终字段作为参数。例如,它可以是某些算法的某个常量变量。但在 java-doc 中我看到: {@lin
我正在尝试一个非常快的方法(~20 us/op),它似乎工作得很好,除了一些随机很长的迭代: Iteration 63: 14.319 us/op Iteration 64: 13.128 us/
我想看看是否有一种方法可以告诉 JMH 仅测量微基准调用的所有方法中的一个特定方法。 我想使用单元测试作为基础自动创建微基准,因此我不必手动构建微基准。在我的研究中,我有一个大型代码库,我在其中进行了
我正在运行 JMH 基准测试: Options opt = new OptionsBuilder() .output("C:/test/infinis
我是一名优秀的程序员,十分优秀!