[ 
https://issues.apache.org/jira/browse/LANG-1576?focusedWorklogId=468402&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-468402
 ]

ASF GitHub Bot logged work on LANG-1576:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 10/Aug/20 04:47
            Start Date: 10/Aug/20 04:47
    Worklog Time Spent: 10m 
      Work Description: XenoAmess commented on a change in pull request #565:
URL: https://github.com/apache/commons-lang/pull/565#discussion_r467686209



##########
File path: src/test/java/org/apache/commons/lang3/StringUtilsChompTest.java
##########
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang3;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.infra.Blackhole;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.commons.lang3.StringUtils.EMPTY;
+import static org.apache.commons.lang3.StringUtils.isEmpty;
+import static org.apache.commons.lang3.StringUtils.length;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@State(Scope.Thread)
+@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Fork(value = 1, jvmArgs = {"-server", "-Xms512M", "-Xmx512M"})
+public class StringUtilsChompTest {
+    // Different code paths with no chomp
+    private static final String string1 = "";
+    private static final String string2 = "a";
+    private static final String string3 = "aa";
+
+    // Single char chomp
+    private static final String string4 = "\r";
+    private static final String string5 = "\n";
+
+    // Multi-char chomp
+    private static final String string6 = "\r\n";
+    private static final String string7 = "a\n";
+    private static final String string8 = "a\r";
+    private static final String string9 = "a\r\n";
+
+    private static final String[] strings = buildStrings();
+
+    private static String[] buildStrings() {
+        String[] res = new String[128 * 128];
+        for (int i = 0; i < 128; i++) {
+            for (int j = 0; j < 128; j++) {
+                StringBuilder stringBuilder = new StringBuilder();
+                stringBuilder.append((char) i);
+                stringBuilder.append((char) j);
+                res[i * 128 + j] = stringBuilder.toString();
+            }
+        }
+        return res;
+    }
+
+    @Benchmark
+    public String test1_Empty_Old() {
+        return chompOld(string1);
+    }
+
+    @Benchmark
+    public String test1_Empty_New() {
+        return chompNew(string1);
+    }
+
+    @Benchmark
+    public String test2_No_Chomp_Old() {
+        return chompOld(string2);
+    }
+
+    @Benchmark
+    public String test2_No_Chomp_New() {
+        return chompNew(string2);
+    }
+
+    @Benchmark
+    public String test3_No_Chomp_Old() {
+        return chompOld(string3);
+    }
+
+    @Benchmark
+    public String test3_No_Chomp_New() {
+        return chompNew(string3);
+    }
+
+    @Benchmark
+    public String test4_R_Old() {
+        return chompOld(string4);
+    }
+
+    @Benchmark
+    public String test4_R_New() {
+        return chompNew(string4);
+    }
+
+    @Benchmark
+    public String test5_N_Old() {
+        return chompOld(string5);
+    }
+
+    @Benchmark
+    public String test5_N_New() {
+        return chompNew(string5);
+    }
+
+    @Benchmark
+    public String test6_R_N_Old() {
+        return chompOld(string6);
+    }
+
+    @Benchmark
+    public String test6_R_N_New() {
+        return chompNew(string6);
+    }
+
+    @Benchmark
+    public String test7_a_N_Old() {
+        return chompOld(string7);
+    }
+
+    @Benchmark
+    public String test7_a_N_New() {
+        return chompNew(string7);
+    }
+
+    @Benchmark
+    public String test8_a_N_Old() {

Review comment:
       @aherbert 
   Thanks for the example.
   Will learn from it when writing other jmh tests.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 468402)
    Time Spent: 5h 10m  (was: 5h)

> refine StringUtils.chomp
> ------------------------
>
>                 Key: LANG-1576
>                 URL: https://issues.apache.org/jira/browse/LANG-1576
>             Project: Commons Lang
>          Issue Type: Sub-task
>            Reporter: Jin Xu
>            Priority: Minor
>          Time Spent: 5h 10m
>  Remaining Estimate: 0h
>
> [https://github.com/apache/commons-lang/pull/565]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to