xiaoxuandev commented on code in PR #3452:
URL: https://github.com/apache/parquet-java/pull/3452#discussion_r2998397530


##########
parquet-benchmarks/src/main/java/org/apache/parquet/benchmarks/VariantBenchmark.java:
##########
@@ -0,0 +1,551 @@
+/*
+ * 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.parquet.benchmarks;
+
+import java.math.BigDecimal;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Random;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import org.apache.parquet.io.api.Binary;
+import org.apache.parquet.io.api.RecordConsumer;
+import org.apache.parquet.schema.GroupType;
+import org.apache.parquet.schema.LogicalTypeAnnotation;
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName;
+import org.apache.parquet.schema.Type.Repetition;
+import org.apache.parquet.schema.Types;
+import org.apache.parquet.variant.Variant;
+import org.apache.parquet.variant.VariantBuilder;
+import org.apache.parquet.variant.VariantObjectBuilder;
+import org.apache.parquet.variant.VariantValueWriter;
+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.Timeout;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.infra.Blackhole;
+
+/**
+ * JMH benchmarks for {@link VariantBuilder}: construction, serialization and 
deserialization of
+ * Variant objects.
+ *
+ * <p>The benchmark mirrors the structure of the Iceberg {@code 
VariantSerializationBenchmark} so
+ * that results from the two projects can be compared directly. Parameters are 
kept identical where
+ * the APIs permit:
+ *
+ * <ul>
+ *   <li>{@link #fieldCount} – total number of top-level fields per object.
+ *   <li>{@link #depth} – {@code Shallow} (primitives only) or {@code Nested} 
(some fields are
+ *       5-field sub-objects).
+ * </ul>
+ *
+ * <p>Unlike the Iceberg benchmark there is no "shredded percent" axis: 
parquet-java's
+ * {@link VariantBuilder} constructs unshredded Variant binary directly; 
shredding is handled
+ * separately by the Parquet writer layer.
+ *
+ * <p>Build and run:
+ *
+ * <pre>
+ *   ./mvnw --projects parquet-benchmarks -amd -DskipTests 
-Denforcer.skip=true clean package
+ *   ./parquet-benchmarks/run.sh all 
org.apache.parquet.benchmarks.VariantBenchmark \
+ *       -wi 5 -i 5 -f 1 -rff /tmp/variant-benchmark.json
+ * </pre>
+ *
+ * Change fork to 1 before merge
+ */
+@Fork(0)
+@State(Scope.Benchmark)
+@Warmup(iterations = 100)
+@Measurement(iterations = 100)
+@BenchmarkMode(Mode.SingleShotTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@Timeout(time = 10, timeUnit = TimeUnit.MINUTES)
+public class VariantBenchmark {
+
+  /** Whether to include nested sub-objects in the field values. */
+  public enum Depth {
+    /** Flat structure: no nesting. */
+    Flat,
+    /** Nested values. */
+    Nested,
+  }
+
+  /**
+   * Iterations on the small benchmarks whose operations are so fast that 
clocks, especially ARM clocks,
+   * can't reliably measure them.
+   */
+  private static final int ITERATIONS = 100;
+
+  /** Total number of top-level fields in each variant object. */
+  @Param({"1000", "10000"})
+  private int fieldCount;
+
+  /** Whether to include nested variant objects as some of the field values. */
+  @Param({"Flat", "Nested"})
+  private Depth depth;
+
+  /**
+   * A counter of strings created; used to ensure limited uniqueness in 
strings.
+   */
+  private static int counter;
+
+  /**
+   * Get a count value.
+   * @return a new value.
+   */
+  private static int count() {
+    int c = counter++;
+    if (c >= 512) {
+      c = 0;

Review Comment:
   only resets the local copy, counter keeps growing?



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