官术网_书友最值得收藏!

Microbenchmarks

Microbenchmarking is used if we want to know which methods perform better than others. A naive approach would wrap the called function inside a block of a measureTimeMillis or measureNanoTime function. These functions just calculate the difference between start and stop timestamps:

public inline fun measureTimeMillis(block: () -> Unit) : Long {
val start = System.currentTimeMillis()
block()
return System.currentTimeMillis() - start
}

At a first glance, this approach gives us an idea about the performance of the code inside the block, but if we perform several experiments, it will be clear that this is the wrong approach. We've already touched on how the JVM executes and changes programming code to perform optimizations. When lines of code are executed, the JVM collects information about them. It will then try to optimize them and collect new information the next time it executes these same lines. Therefore, we have to take into account this factor and measure code after a warm-up to simulate real-world conditions.

To implement microbenchmarking correctly, you have to use the Java Microbenchmark Harness. 

主站蜘蛛池模板: 平武县| 闵行区| 长春市| 通海县| 武安市| 望都县| 志丹县| 清镇市| 永福县| 菏泽市| 页游| 黄陵县| 浦县| 忻州市| 鄂托克旗| 昭苏县| 靖西县| 信丰县| 延长县| 依兰县| 六盘水市| 常宁市| 榆社县| 炉霍县| 呼和浩特市| 平湖市| 固原市| 兰坪| 漳平市| 凤冈县| 黄陵县| 黔东| 栾城县| 河南省| 莱芜市| 浦北县| 金阳县| 阳江市| 蒙自县| 中卫市| 牟定县|