40
40
@ BenchmarkMode (Mode .AverageTime )
41
41
@ OutputTimeUnit (TimeUnit .NANOSECONDS )
42
42
@ State (Scope .Thread )
43
- public class IndexOfBenchmark {
43
+ public class StringIndexOfChar {
44
44
private static final int loops = 100000 ;
45
45
private static final Random rng = new Random (1999 );
46
46
private static final int pathCnt = 1000 ;
@@ -68,7 +68,7 @@ public class IndexOfBenchmark {
68
68
private static String makeRndString (boolean isUtf16 , int length ) {
69
69
StringBuilder sb = new StringBuilder (length );
70
70
if (length > 0 ){
71
- sb .append (isUtf16 ?'☺ ' :'b' );
71
+ sb .append (isUtf16 ?'\u2026 ' :'b' ); // ...
72
72
73
73
for (int i = 1 ; i < length -1 ; i ++) {
74
74
sb .append ((char )('b' + rng .nextInt (26 )));
@@ -81,31 +81,31 @@ private static String makeRndString(boolean isUtf16, int length) {
81
81
82
82
83
83
@ Benchmark
84
- public static void latin1_mixed_char () {
84
+ public void latin1_mixed_char () {
85
85
int ret = 0 ;
86
86
for (String what : latn1_mixedLength ) {
87
87
ret += what .indexOf ('a' );
88
88
}
89
89
}
90
90
91
91
@ Benchmark
92
- public static void utf16_mixed_char () {
92
+ public void utf16_mixed_char () {
93
93
int ret = 0 ;
94
94
for (String what : utf16_mixedLength ) {
95
95
ret += what .indexOf ('a' );
96
96
}
97
97
}
98
98
99
99
@ Benchmark
100
- public static void latin1_mixed_String () {
100
+ public void latin1_mixed_String () {
101
101
int ret = 0 ;
102
102
for (String what : latn1_mixedLength ) {
103
103
ret += what .indexOf ("a" );
104
104
}
105
105
}
106
106
107
107
@ Benchmark
108
- public static void utf16_mixed_String () {
108
+ public void utf16_mixed_String () {
109
109
int ret = 0 ;
110
110
for (String what : utf16_mixedLength ) {
111
111
ret += what .indexOf ("a" );
@@ -115,31 +115,31 @@ public static void utf16_mixed_String() {
115
115
////////// more detailed code path dependent tests //////////
116
116
117
117
@ Benchmark
118
- public static void latin1_Short_char () {
118
+ public void latin1_Short_char () {
119
119
int ret = 0 ;
120
120
for (String what : latn1_short ) {
121
121
ret += what .indexOf ('a' );
122
122
}
123
123
}
124
124
125
125
@ Benchmark
126
- public static void latin1_SSE4_char () {
126
+ public void latin1_SSE4_char () {
127
127
int ret = 0 ;
128
128
for (String what : latn1_sse4 ) {
129
129
ret += what .indexOf ('a' );
130
130
}
131
131
}
132
132
133
133
@ Benchmark
134
- public static void latin1_AVX2_char () {
134
+ public void latin1_AVX2_char () {
135
135
int ret = 0 ;
136
136
for (String what : latn1_avx2 ) {
137
137
ret += what .indexOf ('a' );
138
138
}
139
139
}
140
140
141
141
@ Benchmark
142
- public static int utf16_Short_char () {
142
+ public int utf16_Short_char () {
143
143
int ret = 0 ;
144
144
for (String what : utf16_short ) {
145
145
ret += what .indexOf ('a' );
@@ -148,7 +148,7 @@ public static int utf16_Short_char() {
148
148
}
149
149
150
150
@ Benchmark
151
- public static int utf16_SSE4_char () {
151
+ public int utf16_SSE4_char () {
152
152
int ret = 0 ;
153
153
for (String what : utf16_sse4 ) {
154
154
ret += what .indexOf ('a' );
@@ -157,7 +157,7 @@ public static int utf16_SSE4_char() {
157
157
}
158
158
159
159
@ Benchmark
160
- public static int utf16_AVX2_char () {
160
+ public int utf16_AVX2_char () {
161
161
int ret = 0 ;
162
162
for (String what : utf16_avx2 ) {
163
163
ret += what .indexOf ('a' );
@@ -166,7 +166,7 @@ public static int utf16_AVX2_char() {
166
166
}
167
167
168
168
@ Benchmark
169
- public static int latin1_Short_String () {
169
+ public int latin1_Short_String () {
170
170
int ret = 0 ;
171
171
for (String what : latn1_short ) {
172
172
ret += what .indexOf ("a" );
@@ -175,7 +175,7 @@ public static int latin1_Short_String() {
175
175
}
176
176
177
177
@ Benchmark
178
- public static int latin1_SSE4_String () {
178
+ public int latin1_SSE4_String () {
179
179
int ret = 0 ;
180
180
for (String what : latn1_sse4 ) {
181
181
ret += what .indexOf ("a" );
@@ -184,7 +184,7 @@ public static int latin1_SSE4_String() {
184
184
}
185
185
186
186
@ Benchmark
187
- public static int latin1_AVX2_String () {
187
+ public int latin1_AVX2_String () {
188
188
int ret = 0 ;
189
189
for (String what : latn1_avx2 ) {
190
190
ret += what .indexOf ("a" );
@@ -193,7 +193,7 @@ public static int latin1_AVX2_String() {
193
193
}
194
194
195
195
@ Benchmark
196
- public static int utf16_Short_String () {
196
+ public int utf16_Short_String () {
197
197
int ret = 0 ;
198
198
for (String what : utf16_short ) {
199
199
ret += what .indexOf ("a" );
@@ -202,7 +202,7 @@ public static int utf16_Short_String() {
202
202
}
203
203
204
204
@ Benchmark
205
- public static int utf16_SSE4_String () {
205
+ public int utf16_SSE4_String () {
206
206
int ret = 0 ;
207
207
for (String what : utf16_sse4 ) {
208
208
ret += what .indexOf ("a" );
@@ -211,7 +211,7 @@ public static int utf16_SSE4_String() {
211
211
}
212
212
213
213
@ Benchmark
214
- public static int utf16_AVX2_String () {
214
+ public int utf16_AVX2_String () {
215
215
int ret = 0 ;
216
216
for (String what : utf16_avx2 ) {
217
217
ret += what .indexOf ("a" );
0 commit comments