You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/02/04 01:11:04 UTC

[GitHub] [commons-geometry] aherbert commented on a change in pull request #60: GEOMETRY-75: Performance Module

aherbert commented on a change in pull request #60: GEOMETRY-75: Performance Module
URL: https://github.com/apache/commons-geometry/pull/60#discussion_r374428085
 
 

 ##########
 File path: commons-geometry-examples/examples-jmh/src/main/java/org/apache/commons/geometry/examples/jmh/euclidean/VectorPerformance.java
 ##########
 @@ -0,0 +1,382 @@
+/*
+ * 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.geometry.examples.jmh.euclidean;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.function.DoubleSupplier;
+import java.util.function.Function;
+import java.util.function.ToDoubleFunction;
+import java.util.function.UnaryOperator;
+
+import org.apache.commons.geometry.core.Vector;
+import org.apache.commons.geometry.euclidean.oned.Vector1D;
+import org.apache.commons.geometry.euclidean.threed.Vector3D;
+import org.apache.commons.geometry.euclidean.twod.Vector2D;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.ZigguratNormalizedGaussianSampler;
+import org.apache.commons.rng.simple.RandomSource;
+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;
+
+/**
+ * Benchmarks for the Euclidean vector classes.
+ */
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Fork(value = 1, jvmArgs = {"-server", "-Xms512M", "-Xmx512M"})
+public class VectorPerformance {
+
+    /**
+     * An array of edge numbers that will produce edge case results from functions:
+     * {@code +/-inf, +/-max, +/-min, +/-0, nan}.
+     */
+    private static final double[] EDGE_NUMBERS = {
+        Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.MAX_VALUE,
+        -Double.MAX_VALUE, Double.MIN_VALUE, -Double.MIN_VALUE, 0.0, -0.0, Double.NaN
+    };
+
+    /** String constant used to request random double values. */
+    private static final String RANDOM = "random";
+
+    /** String constant used to request a set of double values capable of normalization. */
+    private static final String NORMALIZABLE = "normalizable";
+
+    /** String constant used to request edge-case double values. */
+    private static final String EDGE = "edge";
+
+    /** Base class for vector inputs.
+     * @param <V> Vector implementation type
+     */
+    @State(Scope.Thread)
+    public abstract static class VectorInputBase<V extends Vector<V>> {
+
+        /** The dimension of the vector. */
+        private final int dimension;
+
+        /** Factory function used to create vectors from arrays of doubles. */
+        private final Function<double[], V> vectorFactory;
+
+        /** The number of vectors in the input list. */
+        @Param({"1000"})
 
 Review comment:
   Have you tried different sizes: 10, 100, 1000, 10000, etc? I would put this as {"100", "10000"} to make a future investigator think about what size they actually require for the benchmark. Small sizes and large sizes will perform differently due to the different memory cache levels and the ability to predict branches (if there are any) on repeat patterns of data.

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


With regards,
Apache Git Services