Skip to content

Instantly share code, notes, and snippets.

@kaneshin
Created March 19, 2015 09:48
Show Gist options
  • Select an option

  • Save kaneshin/9362c86a736e8598f2cc to your computer and use it in GitHub Desktop.

Select an option

Save kaneshin/9362c86a736e8598f2cc to your computer and use it in GitHub Desktop.
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