thhh
05/02/2021, 2:12 PMtime
variable has a redundant initializer which is commented. When you uncomment and use that redundant initializer, program runs a lot faster.
Findings:
when using redundant initializer: 20000100000 in 28ms --> which is quite fast.
when removing redundant initalizer: 20000100000 in 103ms --> which is slow but is recommended by IntelliJ.
IntelliJ hint aside what causes the Kotlin program to run "slower" when NOT using redundant initlializer?diesieben07
05/02/2021, 2:16 PMresult
. The JVM might eliminate the whole computation because it sees that the result is not necessars. Removing the initializer might make that optimization no longer trigger. Proper measurement requires tools such as JMH that have a "black hole" operation that prevents discarding of resultsthhh
05/02/2021, 2:31 PMwe are callingThis is referring to thetwice here, we call it the first time to warm up the processor, to warm up Java and second time we call it and we print out, how long this program takes to execute.compute
time
variable intilizer.
Is this something developers do often and intentionally in other Kotlin code as well?diesieben07
05/02/2021, 2:34 PM