-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString012.java
More file actions
48 lines (37 loc) · 1.27 KB
/
Copy pathString012.java
File metadata and controls
48 lines (37 loc) · 1.27 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
package strings;
/**
* Created by WERT on 09.01.2017.
*/
public class String012 {
private static final int SIZE_OF_STRING = 10_000;
private static long time;
public static void main(String[] args) {
// примеры конкатенации строк
String sl = "";
String so = new String();
StringBuilder sb = new StringBuilder();
System.out.print("\nНа создание строки sl ушло ");
startBenchmark();
for (int i = 0; i < SIZE_OF_STRING; ++i)
sl += "1";
stopBenchmark();
System.out.print("\nНа создание строки so ушло ");
startBenchmark();
for (int i = 0; i < SIZE_OF_STRING; ++i)
so += "1";
stopBenchmark();
System.out.print("\nНа создание строки sb ушло ");
startBenchmark();
for (int i = 0; i < SIZE_OF_STRING; ++i)
sb.append("1");
stopBenchmark();
System.out.println("\nsb.length() = " + sb.length());
}
private static void startBenchmark() {
time = System.currentTimeMillis();
}
private static void stopBenchmark() {
time = System.currentTimeMillis() - time;
System.out.println(time + "мс");
}
}