Skip to content

Commit 91b5220

Browse files
committed
add performance test
1 parent 1b776f6 commit 91b5220

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/main/java/org/apache/commons/lang3/StringUtils.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8191,12 +8191,11 @@ public static String strip(final String str) {
81918191
* @return the stripped String, {@code null} if null String input
81928192
*/
81938193
public static String strip(String str, final String stripChars) {
8194-
final int strLen = length(str);
8195-
if (strLen == 0) {
8194+
int end = length(str);
8195+
if (end == 0) {
81968196
return str;
81978197
}
81988198
int start = 0;
8199-
int end = strLen;
82008199
if (stripChars == null) {
82018200
while (start != end && Character.isWhitespace(str.charAt(start))) {
82028201
start++;
@@ -8214,9 +8213,6 @@ public static String strip(String str, final String stripChars) {
82148213
end--;
82158214
}
82168215
}
8217-
if (start == end) {
8218-
return EMPTY;
8219-
}
82208216
return str.substring(start, end);
82218217
}
82228218

src/test/java/org/apache/commons/lang3/StringUtilsStripTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import java.util.concurrent.TimeUnit;
3131

32-
import static org.apache.commons.lang3.StringUtils.EMPTY;
3332
import static org.apache.commons.lang3.StringUtils.INDEX_NOT_FOUND;
3433
import static org.apache.commons.lang3.StringUtils.isEmpty;
3534
import static org.apache.commons.lang3.StringUtils.length;
@@ -42,6 +41,9 @@
4241
@BenchmarkMode(Mode.AverageTime)
4342
@OutputTimeUnit(TimeUnit.NANOSECONDS)
4443
@State(Scope.Thread)
44+
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
45+
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
46+
@Fork(value = 1, jvmArgs = {"-server", "-Xms512M", "-Xmx512M"})
4547
public class StringUtilsStripTest {
4648
static final String string0 = "a";
4749
static final String string1 = " a";
@@ -240,12 +242,11 @@ public void testStrings1New(Blackhole blackhole) {
240242
//-----
241243

242244
public static String stripNew(String str, final String stripChars) {
243-
final int strLen = length(str);
244-
if (strLen == 0) {
245+
int end = length(str);
246+
if (end == 0) {
245247
return str;
246248
}
247249
int start = 0;
248-
int end = strLen;
249250
if (stripChars == null) {
250251
while (start != end && Character.isWhitespace(str.charAt(start))) {
251252
start++;
@@ -263,9 +264,6 @@ public static String stripNew(String str, final String stripChars) {
263264
end--;
264265
}
265266
}
266-
if (start == end) {
267-
return EMPTY;
268-
}
269267
return str.substring(start, end);
270268
}
271269

0 commit comments

Comments
 (0)