Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
110 lines (91 loc) · 2.99 KB

File metadata and controls

110 lines (91 loc) · 2.99 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package string;
import myutil.Log;
/**
* Created by yahier on 17/5/27.
*/
public class StringBufferTest {
public static final void main(String[] args) {
//test1();
//test2();
//test3();
//test4();
test5();
test6();
}
//9
private static void test1() {
long time1 = System.currentTimeMillis();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 10000; i++) {
buffer.append("我");
buffer.append("是");
buffer.append("一");
buffer.append("滴");
buffer.append("远");
buffer.append("方");
buffer.append("孤");
buffer.append("星");
buffer.append("的");
}
long time2 = System.currentTimeMillis();
Log.e("test1", "time:" + (time2 - time1));
}
//4
private static void test2() {
long time1 = System.currentTimeMillis();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 10000; i++) {
buffer.append("我").append("是").append("一").append("滴").append("远").append("方").append("孤").append("星").append("的");
}
long time2 = System.currentTimeMillis();
Log.e("test2", "time:" + (time2 - time1));
}
//6
private static void test3() {
long time1 = System.currentTimeMillis();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 10000; i++) {
buffer.append('我');
buffer.append('是');
buffer.append('一');
buffer.append('滴');
buffer.append('远');
buffer.append('方');
buffer.append('孤');
buffer.append('星');
buffer.append('的');
}
long time2 = System.currentTimeMillis();
Log.e("test3", "time:" + (time2 - time1));
}
//4
private static void test4() {
long time1 = System.currentTimeMillis();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 10000; i++) {
buffer.append('我').append('是').append('一').append('滴').append('远').append('方').append('孤').append('星').append('的');
}
long time2 = System.currentTimeMillis();
Log.e("test4", "time:" + (time2 - time1));
}
//8
private static void test5() {
long time1 = System.currentTimeMillis();
String str = "yahier is not here";
for (int i = 0; i < 100000; i++) {
int a = str.indexOf("h");
}
long time2 = System.currentTimeMillis();
Log.e("test5", "time:" + (time2 - time1));
}
//5
private static void test6() {
long time1 = System.currentTimeMillis();
String str = "yahier is not here";
for (int i = 0; i < 100000; i++) {
int a = str.indexOf('h');
}
long time2 = System.currentTimeMillis();
Log.e("test6", "time:" + (time2 - time1));
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.