This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git


The following commit(s) were added to refs/heads/master by this push:
     new d6d521ad Fix benchmark
d6d521ad is described below

commit d6d521ad37e07e0a71fb4170f7be468287cc0229
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Dec 5 08:19:57 2025 -0500

    Fix benchmark
    
    Add license header
---
 pom.xml                                            |  7 ++++-
 .../jmh/LongestCommonSubsequencePerformance.java   | 33 ++++++++++------------
 .../commons/text/lcs-perf-analysis-inputs.csv      | 16 ++++++++++-
 3 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/pom.xml b/pom.xml
index f159e872..87903715 100644
--- a/pom.xml
+++ b/pom.xml
@@ -135,6 +135,12 @@
       <version>${jmh.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-csv</artifactId>
+      <version>1.14.1</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <defaultGoal>clean verify apache-rat:check japicmp:cmp checkstyle:check 
pmd:check spotbugs:check javadoc:javadoc</defaultGoal>
@@ -149,7 +155,6 @@
               <inputExclude>src/site/resources/download_text.cgi</inputExclude>
               
<inputExclude>src/site/resources/release-notes/RELEASE-NOTES-*.txt</inputExclude>
               
<inputExclude>src/test/resources/org/apache/commons/text/stringEscapeUtilsTestData.txt</inputExclude>
-              
<inputExclude>src/test/resources/org/apache/commons/text/lcs-perf-analysis-inputs.csv</inputExclude>
               
<inputExclude>src/test/resources/org/apache/commons/text/oss-fuzz/**</inputExclude>
             </inputExcludes>
           </configuration>
diff --git 
a/src/test/java/org/apache/commons/text/jmh/LongestCommonSubsequencePerformance.java
 
b/src/test/java/org/apache/commons/text/jmh/LongestCommonSubsequencePerformance.java
index eef5f9d3..49d1318e 100644
--- 
a/src/test/java/org/apache/commons/text/jmh/LongestCommonSubsequencePerformance.java
+++ 
b/src/test/java/org/apache/commons/text/jmh/LongestCommonSubsequencePerformance.java
@@ -16,16 +16,14 @@
  */
 package org.apache.commons.text.jmh;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.UncheckedIOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.commons.csv.CSVFormat;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.commons.text.similarity.LongestCommonSubsequence;
@@ -114,22 +112,21 @@ public class LongestCommonSubsequencePerformance {
         final List<Pair<CharSequence, CharSequence>> inputs = new 
ArrayList<>();
 
         @Setup(Level.Trial)
-        public void setup() {
+        public void setup() throws IOException {
             final ClassLoader classLoader = 
Thread.currentThread().getContextClassLoader();
-            try (InputStream is = 
classLoader.getResourceAsStream("org/apache/commons/text/lcs-perf-analysis-inputs.csv");
-                 InputStreamReader isr = new 
InputStreamReader(Objects.requireNonNull(is));
-                 BufferedReader br = new BufferedReader(isr)) {
-                String line;
-                while ((line = br.readLine()) != null && 
!line.trim().isEmpty()) {
-                    line = line.trim();
-                    final int indexOfComma = line.indexOf(',');
-                    final String inputA = line.substring(0, indexOfComma);
-                    final String inputB = line.substring(1 + indexOfComma);
-                    this.inputs.add(ImmutablePair.of(inputA, inputB));
-                }
-            } catch (final IOException exception) {
-                throw new UncheckedIOException(exception.getMessage(), 
exception);
-            }
+            
CSVFormat.DEFAULT.builder().setCommentMarker('#').setTrim(true).get()
+                    .parse(new InputStreamReader(
+                            
Objects.requireNonNull(classLoader.getResourceAsStream("org/apache/commons/text/lcs-perf-analysis-inputs.csv"))))
+                    .forEach(record -> {
+                        final String line = record.get(0);
+                        final int indexOfComma = line.indexOf(',');
+                        if (indexOfComma < 0) {
+                            throw new IllegalStateException("Invalid input 
line: " + line);
+                        }
+                        final String inputA = line.substring(0, indexOfComma);
+                        final String inputB = line.substring(1 + indexOfComma);
+                        this.inputs.add(ImmutablePair.of(inputA, inputB));
+                    });
         }
     }
 
diff --git 
a/src/test/resources/org/apache/commons/text/lcs-perf-analysis-inputs.csv 
b/src/test/resources/org/apache/commons/text/lcs-perf-analysis-inputs.csv
index 53610d35..8253e4f6 100644
--- a/src/test/resources/org/apache/commons/text/lcs-perf-analysis-inputs.csv
+++ b/src/test/resources/org/apache/commons/text/lcs-perf-analysis-inputs.csv
@@ -1,4 +1,18 @@
-"This is test data for a JMH (the Java Microbenchmark Harness) which is used 
from the class org.apache.commons.text.jmh.LongestCommonSubsequencePerformance."
+# 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
+#
+#      https://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.
+"This is test data for a JMH (the Java Microbenchmark Harness), which is used 
from the class org.apache.commons.text.jmh.LongestCommonSubsequencePerformance."
 "The quick brown fox jumps over the lazy dog. A man, a plan, a canal, Panama. 
Was it a car or a cat I saw? Step on no pets. Rats live on no evil star."
 "Here, the field iterations will be populated with appropriate values from the 
@Param annotation by the JMH when it is passed to the benchmark method. The 
@Setup annotated method is invoked before each invocation of the benchmark and 
creates a new Hasher ensuring isolation. When the execution is finished, we'll 
get a result similar to the one below: When running microbenchmarks, it's very 
important to be aware of optimizations. Otherwise, they may affect 
the","benchmark results in a very [...]
 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse 
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non 
proident, sunt in culpa qui officia deserunt mollit anim id est laborum. This 
code is free software; you can redistrib [...]

Reply via email to