When I run my function in junit test i have time about 1000 faster then with bootRun. When I set in build.gradle.kts
tasks.getByName<org.springframework.boot.gradle.tasks.run.BootRun>("bootRun") {
isOptimizedLaunch = false
}
time is equal then test run. Why it happens? How I can optimize bootJar? bootJar hasn't parameter isOptimizedLaunch
Function example
package com.example.demo
import java.util.concurrent.TimeUnit
class LongFun {
fun main() {
val startTime = System.nanoTime()
for (i1 in 0..10000) {
longFun(1000)
}
val endTime = System.nanoTime()
val durationInNano = endTime - startTime //Total execution time in nano seconds
var durationInMillis = TimeUnit.NANOSECONDS.toMillis(durationInNano)
println("time=$durationInMillis")
}
fun longFun(n: Int) {
for (i2 in 0..n) {
for (i3 in 0..n) {
var a = 1
}
}
}
}
The full code I did with https://start.spring.io/ (gradle, kotlin) and didn't change anything
UPDATE1. It is a simple example, in real the same problem in my app with optaplanner, it also has many calculations.
UPDATE2. With maven i have the same bad result
- In test - 2ms
- In gradle with isOptimizedLaunch = false - 2ms
- In gradle without isOptimizedLaunch = false - 5245ms
- In maven - 5146ms