Created
March 19, 2015 09:48
-
-
Save kaneshin/9362c86a736e8598f2cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class string { | |
| public static void main(String[] args) { | |
| final int NN = 40000; | |
| final int N = 20000000; | |
| long t; | |
| { | |
| t = System.currentTimeMillis(); | |
| String s = new String(); | |
| for (int i = NN; i-- > 0 ;) { | |
| s += "s"; | |
| } | |
| System.out.println(System.currentTimeMillis() - t); | |
| } | |
| { | |
| t = System.currentTimeMillis(); | |
| StringBuffer sb = new StringBuffer(); | |
| for (int i = N; i-- > 0 ;) { | |
| sb.append("s"); | |
| } | |
| System.out.println(System.currentTimeMillis() - t); | |
| } | |
| { | |
| t = System.currentTimeMillis(); | |
| StringBuilder sb = new StringBuilder(); | |
| for (int i = N; i-- > 0 ;) { | |
| sb.append("s"); | |
| } | |
| System.out.println(System.currentTimeMillis() - t); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment