I use JMH to specify the complexity of the operation. If you've never worked with JMH, don't worry. JMH will just launch the estimateOperation
method multiple times and then get the average time.
Question: [narrow] will this program calculate Math.cbrt(Integer.MAX_VALUE)
each time? Or it just calculate it once and return cached result afterwards?
@GenerateMicroBenchmark
public void estimateOperation() {
calculate();
}
public int calculate() {
return Math.cbrt(Integer.MAX_VALUE);
}
Question: [broad]: Does JVM ever cache the result of the methods?
calculate()
come in? – Monsoon