-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-vs-stringbuilder.html
More file actions
49 lines (45 loc) · 1.4 KB
/
Copy pathstring-vs-stringbuilder.html
File metadata and controls
49 lines (45 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
public static void main(String[] args) {
String s = "";
long tempsDebutString = System.currentTimeMillis();
for(int i=0; i<200;i++){
for(int j=0; j<200;j++){
s += "+ x_" + i + "_" + j+"ok";
}
}
long tempsFinString = System.currentTimeMillis();
float secondsString = (tempsFinString - tempsDebutString) / 1000F;
System.out.println(secondsString);
StringBuilder sb = new StringBuilder();
long tempsDebutStringBuilder = System.currentTimeMillis();
for(int i=0; i<200;i++){
sb = new StringBuilder();
for(int j=0; j<200;j++){
sb.append("+ x_");
sb.append(i);
sb.append("_");
sb.append(j);
sb.append("ok");
}
}
long tempsFinStringBuilder = System.currentTimeMillis();
float secondsStringBuilder = (tempsFinStringBuilder - tempsDebutStringBuilder) / 1000F;
System.out.println(secondsStringBuilder);
final String X = "+ x_";
final String U = "_";
final String O = "ok";
sb = new StringBuilder();
long tempsDebutStringBuilder2 = System.currentTimeMillis();
for(int i=0; i<200;i++){
sb = new StringBuilder();
for(int j=0; j<200;j++){
sb.append(X);
sb.append(i);
sb.append(U);
sb.append(j);
sb.append(O);
}
}
long tempsFinStringBuilder2 = System.currentTimeMillis();
float secondsStringBuilder2 = (tempsFinStringBuilder2 - tempsDebutStringBuilder2) / 1000F;
System.out.println(secondsStringBuilder2);
}