@@ -0,0 +1,1361 @@
+package pl.ciruk.blog.jitest;%0A%0Aimport com.google.common.base.Stopwatch;%0Aimport org.junit.Test;%0A%0Aimport java.util.concurrent.TimeUnit;%0A%0Apublic class EmptyLoopTest %7B%0A    @Test(timeout = 100_000L)%0A    public void shouldEliminateEmptyIntLoop() throws Exception %7B%0A        for (int i = 0; i %3C 100; i++) %7B%0A            runAndMeasureTime(this::intLoop);%0A        %7D%0A    %7D%0A%0A    @Test(timeout = 100_000L)%0A    public void shouldEliminateEmptyIntToLongLoop() throws Exception %7B%0A        for (int i = 0; i %3C 100; i++) %7B%0A            runAndMeasureTime(this::intToLongLoop);%0A        %7D%0A    %7D%0A%0A    @Test(timeout = 100_000L)%0A    public void shouldEliminateEmptyLongLoop() throws Exception %7B%0A        for (int i = 0; i %3C 100; i++) %7B%0A            runAndMeasureTime(this::longLoop);%0A        %7D%0A    %7D%0A%0A    private void intLoop() %7B%0A        for (int i = 0; i %3C 20_000_000; i++) %7B%0A%0A        %7D%0A    %7D%0A%0A    private void intToLongLoop() %7B%0A        for (int i = 0; i %3C 2_000_000_000L; i++) %7B%0A            // no-op%0A        %7D%0A    %7D%0A%0A    private void longLoop() %7B%0A        for (long i = 0; i %3C 2_000_000_000L; i++) %7B%0A            // no-op%0A        %7D%0A    %7D%0A%0A    private void runAndMeasureTime(Runnable runnable) %7B%0A        Stopwatch stopwatch = Stopwatch.createStarted();%0A        runnable.run();%0A        stopwatch.stop();%0A        System.out.printf(%22%25d ms%25n%22, stopwatch.elapsed(TimeUnit.MILLISECONDS));%0A    %7D%0A%7D%0A

Verify JIT behaviour on empty loops