What you're observing has to do with the JVM warm-up and the nature of a JIT compiler that optimizes code at runtime.
There's a whole article about that topic on Baeldung.com
I'd suggest you use the "JHM - Java Microbenchmark Harness" framework mentioned in the article for benchmarking your program.