为什么我们必须固定每次测量迭代的持续时间?
why do we have to fix the duration for each measurement iteration?
迭代时间是什么意思?
@Measurement(iterations = 50, time = 2)
是否应该固定测量的时间,如果测量的迭代时间超过2秒,迭代将停止?如果那是真的,这对测量有什么影响。
Allows you to provide the actual test phase parameters. You can specify number of iterations, how long to run each iteration and number of test invocations in the iteration (usually used with @BenchmarkMode(Mode.SingleShotTime) to measure the cost of a group of operations – instead of using loops).
该问题的直接答案是:"We have to provide the iteration time (or rely on the default iteration time), because otherwise the iteration will never stop"。根据基准测试模式,迭代时间的含义可能不同。例如,Javadoc says:
/**
* <p>Throughput: operations per unit of time.</p>
*
* <p>Runs by continuously calling {@link Benchmark} methods,
* counting the total throughput over all worker threads.
* This mode is time-based, and it will run until the iteration
* time expires.</p>
*/
Throughput("thrpt", "Throughput, ops/time"),
在 Java 中无法停止不合作的执行,除非杀死 VM。 (中断线程需要合作:那里应该检查中断)。因此,如果 @Benchmark
调用花费的时间比请求的迭代时间长,我们除了等待之外别无选择。
迭代时间是什么意思?
@Measurement(iterations = 50, time = 2)
是否应该固定测量的时间,如果测量的迭代时间超过2秒,迭代将停止?如果那是真的,这对测量有什么影响。
Allows you to provide the actual test phase parameters. You can specify number of iterations, how long to run each iteration and number of test invocations in the iteration (usually used with @BenchmarkMode(Mode.SingleShotTime) to measure the cost of a group of operations – instead of using loops).
该问题的直接答案是:"We have to provide the iteration time (or rely on the default iteration time), because otherwise the iteration will never stop"。根据基准测试模式,迭代时间的含义可能不同。例如,Javadoc says:
/**
* <p>Throughput: operations per unit of time.</p>
*
* <p>Runs by continuously calling {@link Benchmark} methods,
* counting the total throughput over all worker threads.
* This mode is time-based, and it will run until the iteration
* time expires.</p>
*/
Throughput("thrpt", "Throughput, ops/time"),
在 Java 中无法停止不合作的执行,除非杀死 VM。 (中断线程需要合作:那里应该检查中断)。因此,如果 @Benchmark
调用花费的时间比请求的迭代时间长,我们除了等待之外别无选择。