@@ -0,0 +1,988 @@
+%0Apackage net.restlesscoder.sandbox;%0A%0A/**%0A * A stupid micro-benchmark for branching performance.%0A * %3Cp%3E%0A * It's not shocking that branching in a loop can have a performance impact.%0A * %3C/p%3E%0A */%0Apublic class BranchPerformance %7B%0A%0A%09private static final long ITER = 10000000000L;%0A%0A%09public static boolean condition(long q) %7B%0A%09%09return q %3E ITER / 2;%0A%09%7D%0A%0A%09public static void main(final String... args) throws Exception %7B%0A%09%09timeCondition();%0A%09%09timeNoCondition();%0A%09%7D%0A%0A%09public static void timeCondition() %7B%0A%09%09final long start = System.currentTimeMillis();%0A%09%09long q = 0;%0A%09%09for (long i = 0; i %3C ITER; i++) %7B%0A%09%09%09if (condition(i)) q++;%0A%09%09%7D%0A%09%09final long end = System.currentTimeMillis();%0A%09%09System.out.println((end - start) + %22 (q=%22 + q + %22)%22);%0A%09%7D%0A%0A%09public static void timeNoCondition() %7B%0A%09%09final long start = System.currentTimeMillis();%0A%09%09long q = 0;%0A%09%09for (long i = 0; i %3C ITER; i++) %7B%0A%09%09%09q++;%0A%09%09%7D%0A%09%09final long end = System.currentTimeMillis();%0A%09%09System.out.println((end - start) + %22 (q=%22 + q + %22)%22);%0A%09%7D%0A%7D%0A

Add a microbenchmark for branching in a loop