2015-04-01 27 views

回答

1

該問題的直接答案是:「我們必須提供迭代時間(或依賴於默認的迭代時間),否則迭代將永不停止」。根據基準模式,迭代時間的含義可能不同。例如,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調用需要比所請求的迭代時間更長的時間,除了等待它之外,我們別無選擇。

1

documentation

允許您提供實際的測試階段參數。您可以指定迭代次數,每次迭代運行多長時間以及迭代中的測試調用次數(通常與@BenchmarkMode(Mode.SingleShotTime)一起使用,以測量一組操作的代價 - 而不是使用循環)。

+2

如果您要引用文檔,請明確說明您正在做什麼。 (並不是說我認爲它足以回答這個問題,它自己。) – 2015-04-01 12:56:03

+0

@JonSkeet謝謝,是的確定... – 2015-04-01 12:57:04

+1

此外,java-performance.info是* NOT *是JMH的權威性文檔源,應該是如此標記。引用Javadocs作爲「文檔」是很好的。 – 2015-04-01 13:57:16

相關問題