neoremind commented on code in PR #16280:
URL: https://github.com/apache/lucene/pull/16280#discussion_r3490500640


##########
lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/ByteBuffersDataOutputWriteStringBenchmark.java:
##########
@@ -0,0 +1,336 @@
+/*
+ * 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.lucene.benchmark.jmh;
+
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+import org.apache.lucene.store.ByteBuffersDataOutput;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Measurement;
+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;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.infra.Blackhole;
+
+@BenchmarkMode(Mode.Throughput)
+@OutputTimeUnit(TimeUnit.SECONDS)
+@State(Scope.Benchmark)
+@Warmup(iterations = 5, time = 3)
+@Measurement(iterations = 5, time = 3)
+@Fork(
+    value = 3,
+    jvmArgsAppend = {"-Xmx1g", "-Xms1g", "-XX:+AlwaysPreTouch"})
+public class ByteBuffersDataOutputWriteStringBenchmark {
+
+  private static final int STRING_POOL_SIZE = 8192;
+
+  @Param({
+    "ascii_1",
+    "ascii_10",
+    "ascii_20",
+    "ascii_30",
+    "ascii_40",
+    "ascii_medium",
+    "ascii_long",
+    "ascii_vlarge",
+    "cjk_1",
+    "cjk_10",
+    "cjk_20",
+    "cjk_30",
+    "cjk_40",
+    "cjk_medium",
+    "cjk_long",
+    "cjk_vlarge",
+    "latin_ext_1",
+    "latin_ext_10",
+    "latin_ext_20",
+    "latin_ext_30",
+    "latin_ext_40",
+    "latin_ext_medium",
+    "latin_ext_long",
+    "latin_ext_vlarge",
+    "mixed"
+  })
+  public String stringType;
+
+  /** Target bytes to write per invocation. */
+  @Param({"81920", "491520", "2097152"})
+  public int targetBytes;
+
+  /** Pre-generated strings to write. */
+  private String[] testStrings;
+
+  /** Number of strings to write per invocation to reach targetBytes total 
output. */
+  private int stringsPerInvocation;
+
+  private ByteBuffersDataOutput reusableOutput;
+
+  @Setup(Level.Trial)
+  public void setup() {
+    Random random = new Random(42);
+    testStrings = new String[STRING_POOL_SIZE];
+
+    int avgBytesPerString;
+    switch (stringType) {
+      case "ascii_1":
+        for (int i = 0; i < STRING_POOL_SIZE; i++) {
+          testStrings[i] = randomAscii(random, 1);
+        }
+        avgBytesPerString = 2;
+        break;
+      case "ascii_10":
+        for (int i = 0; i < STRING_POOL_SIZE; i++) {
+          testStrings[i] = randomAscii(random, 8 + random.nextInt(5));
+        }

Review Comment:
   Thanks for the merge and the cleanup, @dweiss ! Yes, the test data prep is 
generated with my check and manual tweaks. The hardcoded avg lengths were meant 
for approximation, I figured it didn't affect correctness. But your Supplier + 
switch approach is much cleaner and strictly accurate. I should have done it 
that way. Appreciated!



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

To unsubscribe, e-mail: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to