package com.netflix.config;

/**
 * Simple benchmark impl to compare the caching of primitive boolean value in CachedDynamicBooleanProperty with
 * the original implementation.
 *
 * @author Mike Smith
 * Date: 11/25/15
 */
public class CachedPropertiesPerfTest
{
    public static void main(String[] args)
    {
        try {
            long loopCount = 4000000000l;

            // Run twice.
            runTest(loopCount);
            runTest(loopCount);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

    private static void runTest(long loopCount)
    {
        // Warmup and then run benchmark.
        DynamicBooleanProperty newProp = new CachedDynamicBooleanProperty("zuul.test.cachedprops.new", true);
        runDynamicBooleanPropertyTest(newProp, 10000);
        long durationPrimitive = runDynamicBooleanPropertyTest(newProp, loopCount);

        // Warmup and then run benchmark.
        DynamicBooleanProperty oldProp = new DynamicBooleanProperty("zuul.test.cachedprops.original", true);
        runDynamicBooleanPropertyTest(oldProp, 10000);
        long durationOriginal = runDynamicBooleanPropertyTest(oldProp, loopCount);

        System.out.println("#####################");
        System.out.println("DynamicBooleanProperty totalled " + durationOriginal + " ms.");
        System.out.println("CachedDynamicBooleanProperty totalled " + durationPrimitive + " ms.");
    }

    private static long runDynamicBooleanPropertyTest(DynamicBooleanProperty prop, long loopCount)
    {
        long startTime = System.currentTimeMillis();

        boolean value;
        for (long i=0; i<loopCount; i++) {
            value = prop.get();
        }

        return System.currentTimeMillis() - startTime;
    }
}

@@ -878,32 +878,113 @@
 rop, loopCount);
+%0A        double avgPrimitiveNs = (durationPrimitive * 1000d * 1000d) / loopCount;
 %0A%0A        // War
@@ -1257,16 +1257,95 @@
 pCount);
+%0A        double avgOriginalNs = (durationOriginal * 1000d * 1000d) / loopCount;
 %0A%0A      
@@ -1445,143 +1445,264 @@
 erty
- totalled %22 + durationOriginal + %22 ms.%22);%0A        System.out.println(%22CachedDynamicBooleanProperty totalled %22 + durationPrimitive + %22 m
+: %22 + loopCount + %22 calls. Total = %22 + durationOriginal + %22 ms. Avg = %22 + avgOriginalNs + %22 nanos.%22);%0A        System.out.println(%22CachedDynamicBooleanProperty: %22 + loopCount + %22 calls. Total = %22 + durationPrimitive + %22 ms. Avg = %22 + avgPrimitiveNs + %22 nano
 s.%22)

Add some more info the CachedPropertiesPerfTest output