This is an automated email from the ASF dual-hosted git repository. placave pushed a commit to branch optimize-hll-union-bench in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
commit a53cd18e6a5876cf1892f027b094c46339a3717f Author: Pierre Lacave <[email protected]> AuthorDate: Mon Jun 10 17:17:58 2024 +0200 Optimise HLL union for mergeHLLtoHLL --- pom.xml | 16 +++++ .../java/org/apache/datasketches/hll/Union.java | 6 +- .../apache/datasketches/hll/BenchmarkUnion.java | 70 ++++++++++++++++++++++ 3 files changed, 89 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 35107f24..456936de 100644 --- a/pom.xml +++ b/pom.xml @@ -89,6 +89,7 @@ under the License. <!-- Test --> <testng.version>7.5.1</testng.version> + <jmh.version>1.37</jmh.version> <!-- these are TestNG groups used for excluding / including groups of tests. See profiles section. --> <testng.generate-java-files>generate_java_files</testng.generate-java-files> <testng.check-cpp-files>check_cpp_files</testng.check-cpp-files> @@ -148,6 +149,12 @@ under the License. <version>${testng.version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.openjdk.jmh</groupId> + <artifactId>jmh-core</artifactId> + <version>${jmh.version}</version> + <scope>test</scope> + </dependency> <!-- <dependency> <groupId>org.apache.datasketches</groupId> @@ -170,6 +177,15 @@ under the License. <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>${maven-compiler-plugin.version}</version> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>org.openjdk.jmh</groupId> + <artifactId>jmh-generator-annprocess</artifactId> + <version>${jmh.version}</version> + </path> + </annotationProcessorPaths> + </configuration> </plugin> <plugin> diff --git a/src/main/java/org/apache/datasketches/hll/Union.java b/src/main/java/org/apache/datasketches/hll/Union.java index 530f646f..c79996b8 100644 --- a/src/main/java/org/apache/datasketches/hll/Union.java +++ b/src/main/java/org/apache/datasketches/hll/Union.java @@ -505,9 +505,9 @@ public class Union extends BaseHllSketch { final byte[] srcArr = ((Hll8Array) src.hllSketchImpl).hllByteArr; final byte[] tgtArr = ((Hll8Array) tgt.hllSketchImpl).hllByteArr; for (int i = 0; i < srcK; i++) { - final byte srcV = srcArr[i]; - final byte tgtV = tgtArr[i]; - tgtArr[i] = (byte) Math.max(srcV, tgtV); + if (srcArr[i] > tgtArr[i]) { + tgtArr[i] = srcArr[i]; + } } break; } diff --git a/src/test/java/org/apache/datasketches/hll/BenchmarkUnion.java b/src/test/java/org/apache/datasketches/hll/BenchmarkUnion.java new file mode 100644 index 00000000..6e77730d --- /dev/null +++ b/src/test/java/org/apache/datasketches/hll/BenchmarkUnion.java @@ -0,0 +1,70 @@ +/* + * 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.datasketches.hll; + +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.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; +import java.util.concurrent.TimeUnit; + +import static org.apache.datasketches.hll.TgtHllType.HLL_8; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Benchmark) +public class BenchmarkUnion { + private HllSketch sketch; + + public static void main(String[] args) throws RunnerException { + Options opt = + new OptionsBuilder() + .include(BenchmarkUnion.class.getSimpleName()) + .forks(1) + .build(); + + new Runner(opt).run(); + } + + + @Setup + public void setup() { + sketch = new HllSketch(11, HLL_8); + for (int i = 0; i < 29197004; i++) { + sketch.update(i); + } + } + + @Benchmark + public void benchBigIntVectorScalarToScalar() { + Union union = new Union(11); + for (int i = 0; i < 1_000_000; i++) { + union.update(sketch); + } + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
