gpt4 book ai didi

java - jmh中的@Group和@GroupThreads指的是什么?

转载 作者:行者123 更新时间:2023-11-29 03:09:38 25 4
gpt4 key购买 nike

我一直在研究 jmh 实现“多线程”基准测试的方式。据我了解,注释 @Group("Identifier")@GroupThreads(thread_number) 允许并行运行同一组内的基准测试。

@Benchmark
@Group("parallel")
@GroupThreads(1)
public void benchmark_1() {
while(true) {}
}

@Benchmark
@Group("parallel")
@GroupThreads(1)
public void benchmark_2() {
while(true) {}
}

使用 CPU 监视器,我发现两个 CPU 已被完全使用。我想知道运行者如何解释这些注释。

最佳答案

您尝试过阅读 Javadocs 吗?那些没有回答问题吗?

例如@Group 说:

 * <p>Multiple {@link Benchmark} methods can be bound in the execution group
* to produce the asymmetric benchmark. Each execution group contains of one
* or more threads. Each thread within a particular execution group executes
* one of {@link Group}-annotated {@link Benchmark} methods. The number of
* threads executing a particular {@link Benchmark} defaults to a single thread,
* and can be overridden by {@link GroupThreads}.</p>
*
* <p>Multiple copies of an execution group may participate in the run, and
* the number of groups depends on the number of worker threads requested.
* JMH will take the requested number of worker threads, round it up to execution
* group size, and then distribute the threads among the (multiple) groups.
* Among other things, this guarantees fully-populated execution groups.</p>

* <p>For example, running {@link Group} with two {@link Benchmark} methods,
* each having {@link GroupThreads}(4), will run 8*N threads, where N is an
* integer.</p>

因此,@Group 产生了一个非对称基准,@GroupThreads 控制线程在组内的分布(-tg ... 在CLI 配音)。 @Threads 表示总共要运行多少个线程(-t ... 在 CLI 中称为它)。

关于java - jmh中的@Group和@GroupThreads指的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30118050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com