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-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new ecdd2d3c9 Add NetBean IDE metadata files to .gitignore
ecdd2d3c9 is described below

commit ecdd2d3c91f111a6c531a4c5211b4b38362f3c68
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Dec 6 11:40:03 2025 -0500

    Add NetBean IDE metadata files to .gitignore
---
 .gitignore                                         |  4 +
 .../lang3/StringUtilsGetDigitsBenchmark.java       | 92 ++++++++++++++++++++++
 2 files changed, 96 insertions(+)

diff --git a/.gitignore b/.gitignore
index 98b2ff55c..ed4144aa1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,3 +22,7 @@ site-content
 # jenv's version file
 .java-version
 /.DS_Store
+
+# NetBeans files
+nb-configuration.xml
+nbactions.xml
diff --git 
a/src/test/java/org/apache/commons/lang3/StringUtilsGetDigitsBenchmark.java 
b/src/test/java/org/apache/commons/lang3/StringUtilsGetDigitsBenchmark.java
new file mode 100644
index 000000000..7410c6ce1
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsGetDigitsBenchmark.java
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+
+package org.apache.commons.lang3;
+
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@State(Scope.Thread)
+public class StringUtilsGetDigitsBenchmark {
+
+    public static String getDigitsManually(final String str) {
+        if (StringUtils.isEmpty(str)) {
+            return str;
+        }
+        final int len = str.length();
+        final char[] buffer = new char[len];
+        int count = 0;
+        for (int i = 0; i < len; i++) {
+            final char tempChar = str.charAt(i);
+            if (Character.isDigit(tempChar)) {
+                buffer[count++] = tempChar;
+            }
+        }
+        return new String(buffer, 0, count);
+    }
+    public static String getDigitsWithBuilder(final String str) {
+        if (StringUtils.isEmpty(str)) {
+            return str;
+        }
+        final int sz = str.length();
+        final StringBuilder strDigits = new StringBuilder(sz);
+        for (int i = 0; i < sz; i++) {
+            final char tempChar = str.charAt(i);
+            if (Character.isDigit(tempChar)) {
+                strDigits.append(tempChar);
+            }
+        }
+        return strDigits.toString();
+    }
+
+    @Param({ "10", "100", "1000", "10000" })
+    public int length;
+
+    private String testStr;
+
+    @Setup(Level.Invocation)
+    public void setup() {
+        final StringBuilder sb = new StringBuilder(length);
+        for (int i = 0; i < length; i++) {
+            final int code = ThreadLocalRandom.current().nextInt(33, 127);
+            sb.append((char) code);
+        }
+        testStr = sb.toString();
+    }
+
+    @Benchmark
+    public String testGetDigitsManually() {
+        return getDigitsManually(testStr);
+    }
+
+    @Benchmark
+    public String testGetDigitsWithBuilder() {
+        return getDigitsWithBuilder(testStr);
+    }
+}
\ No newline at end of file

Reply via email to