sebbASF commented on a change in pull request #565:
URL: https://github.com/apache/commons-lang/pull/565#discussion_r460587706



##########
File path: src/test/java/org/apache/commons/lang3/StringUtilsChompTest.java
##########
@@ -0,0 +1,133 @@
+/*
+ * 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 java.util.concurrent.TimeUnit;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+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 static org.apache.commons.lang3.StringUtils.EMPTY;
+import static org.apache.commons.lang3.StringUtils.isEmpty;
+import static org.apache.commons.lang3.StringUtils.length;
+
+/**
+ * Test to show whether using BitSet for removeAll() methods is faster than 
using HashSet.
+ */
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@State(Scope.Thread)
+public class StringUtilsChompTest {
+
+    private static final String string1 = "\r";
+    private static final String string2 = buildString2();
+
+    private static String buildString2() {
+        StringBuilder stringBuilder = new StringBuilder();
+        for (int i = 0; i < 100000; i++) {
+            stringBuilder.append('0');
+            stringBuilder.append('\r');
+            stringBuilder.append('0');
+            stringBuilder.append('\n');
+            stringBuilder.append('0');
+            stringBuilder.append('\r');
+            stringBuilder.append('\n');
+        }
+        return stringBuilder.toString();
+    }
+
+    @Benchmark
+    public void test1Old() {
+        chompOld(string1);

Review comment:
       The JVM is free to discard code that does nothing useful.
   
https://stackoverflow.com/questions/4871550/how-can-i-be-sure-that-the-compiler-doesnt-optimize-away-my-performance-test




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to