-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTesteStringBuffer.java
More file actions
32 lines (25 loc) · 829 Bytes
/
Copy pathTesteStringBuffer.java
File metadata and controls
32 lines (25 loc) · 829 Bytes
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
package controller;
public class TesteStringBuffer {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
String texto = "";
for (int i = 0; i < 30000; i++) {
texto += i + ", ";
}
long endTime = System.currentTimeMillis();
long diff1 = endTime - startTime;
long startTime1 = System.currentTimeMillis();
StringBuffer sb = new StringBuffer("");
for (int i = 0; i < 30000; i++) {
sb.append(i + ", ");
}
long endTime1 = System.currentTimeMillis();
long diff2 = endTime1 - startTime1;
System.out.println("String normal");
// System.out.println(texto);
System.out.printf("Foram gastos %d milisegundos\n", diff1);
System.out.println("StringBuffer");
// System.out.println(sb.toString());
System.out.printf("Foram gastos %d milisegundos\n", diff2);
}
}