@@ -0,0 +1,2163 @@
+package com.yuzhouwan.hacker.algorithms.thread.sync;%0A%0Aimport org.junit.Test;%0A%0A/**%0A * Copyright @ 2017 yuzhouwan.com%0A * All right reserved.%0A * Function%EF%BC%9AString Buffer Test%0A *%0A * @author Benedict Jin%0A * @since 2017/9/28%0A */%0Apublic class StringBufferTest %7B%0A%0A    public static void strBufferWithoutSync() %7B%0A        StringBuffer buffer = new StringBuffer();%0A        for (int i = 0; i %3C 9999999; i++) %7B%0A            buffer.append(i);%0A            buffer.delete(0, buffer.length() - 1);%0A        %7D%0A    %7D%0A%0A    public static void strBufferWithSync() %7B%0A        StringBuffer buffer = new StringBuffer();%0A        synchronized (buffer) %7B%0A            for (int i = 0; i %3C 9999999; i++) %7B%0A                buffer.append(i);%0A                buffer.delete(0, buffer.length() - 1);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static void strBuilderWithSync() %7B%0A        StringBuilder buffer = new StringBuilder();%0A        synchronized (buffer) %7B%0A            for (int i = 0; i %3C 9999999; i++) %7B%0A                buffer.append(i);%0A                buffer.delete(0, buffer.length() - 1);%0A            %7D%0A        %7D%0A    %7D%0A%0A    /*%0A     * 1.8.0_111%0A     * StringBuffer without sync: 244%0A     * StringBuffer with sync:    236%0A     * StringBuilder with sync:   236%0A     */%0A    @Test%0A    public void test() %7B%0A        System.out.println(System.getProperty(%22java.version%22));%0A        // warm up for jit%0A        for (int i = 0; i %3C 10; i++) %7B%0A            strBufferWithoutSync();%0A            strBufferWithSync();%0A            strBuilderWithSync();%0A        %7D%0A%0A        long start = System.currentTimeMillis();%0A        strBufferWithoutSync();%0A        long end = System.currentTimeMillis();%0A        long time = end - start;%0A        System.out.println(%22StringBuffer without sync: %22 + time);%0A%0A        start = System.currentTimeMillis();%0A        strBufferWithSync();%0A        end = System.currentTimeMillis();%0A        time = end - start;%0A        System.out.println(%22StringBuffer with sync: %22 + time);%0A%0A        start = System.currentTimeMillis();%0A        strBuilderWithSync();%0A        end = System.currentTimeMillis();%0A        time = end - start;%0A        System.out.println(%22StringBuilder with sync: %22 + time);%0A    %7D%0A%7D%0A

Add stringbuffer with sync test