This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git


The following commit(s) were added to refs/heads/master by this push:
     new b6d5f50  Ensure same samplers are tested in single and sequential
b6d5f50 is described below

commit b6d5f5047aff571ead614bef3241881a391caee6
Author: Alex Herbert <aherb...@apache.org>
AuthorDate: Wed Aug 25 09:40:28 2021 +0100

    Ensure same samplers are tested in single and sequential
    
    Use a base class to define the samplers.
---
 .../distribution/ZigguratSamplerPerformance.java   | 97 ++++++++++------------
 1 file changed, 45 insertions(+), 52 deletions(-)

diff --git 
a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/sampling/distribution/ZigguratSamplerPerformance.java
 
b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/sampling/distribution/ZigguratSamplerPerformance.java
index b8531ce..f681ecc 100644
--- 
a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/sampling/distribution/ZigguratSamplerPerformance.java
+++ 
b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/sampling/distribution/ZigguratSamplerPerformance.java
@@ -249,23 +249,9 @@ public class ZigguratSamplerPerformance {
 
     /**
      * The samplers to use for testing the ziggurat method.
-     * Defines the RandomSource and the sampler type.
      */
     @State(Scope.Benchmark)
-    public static class Sources {
-        /**
-         * RNG providers.
-         *
-         * <p>Use different speeds.</p>
-         *
-         * @see <a 
href="https://commons.apache.org/proper/commons-rng/userguide/rng.html";>
-         *      Commons RNG user guide</a>
-         */
-        @Param({"XO_RO_SHI_RO_128_PP",
-                "MWC_256",
-                "JDK"})
-        private String randomSourceName;
-
+    public abstract static class Sources {
         /**
          * The sampler type.
          */
@@ -280,25 +266,7 @@ public class ZigguratSamplerPerformance {
                 MOD_EXPONENTIAL2, MOD_EXPONENTIAL_SIMPLE_OVERHANGS, 
MOD_EXPONENTIAL_INLINING,
                 MOD_EXPONENTIAL_LOOP, MOD_EXPONENTIAL_LOOP2,
                 MOD_EXPONENTIAL_RECURSION, MOD_EXPONENTIAL_INT_MAP, 
MOD_EXPONENTIAL_512})
-        private String type;
-
-        /** The sampler. */
-        private ContinuousSampler sampler;
-
-        /**
-         * @return the sampler.
-         */
-        public ContinuousSampler getSampler() {
-            return sampler;
-        }
-
-        /** Instantiates sampler. */
-        @Setup
-        public void setup() {
-            final RandomSource randomSource = 
RandomSource.valueOf(randomSourceName);
-            final UniformRandomProvider rng = randomSource.create();
-            sampler = createSampler(type, rng);
-        }
+        protected String type;
 
         /**
          * Creates the sampler.
@@ -353,6 +321,44 @@ public class ZigguratSamplerPerformance {
     }
 
     /**
+     * The samplers to use for testing the ziggurat method with single sample 
generation.
+     * Defines the RandomSource and the sampler type.
+     */
+    @State(Scope.Benchmark)
+    public static class SingleSources extends Sources {
+        /**
+         * RNG providers.
+         *
+         * <p>Use different speeds.</p>
+         *
+         * @see <a 
href="https://commons.apache.org/proper/commons-rng/userguide/rng.html";>
+         *      Commons RNG user guide</a>
+         */
+        @Param({"XO_RO_SHI_RO_128_PP",
+                "MWC_256",
+                "JDK"})
+        private String randomSourceName;
+
+        /** The sampler. */
+        private ContinuousSampler sampler;
+
+        /**
+         * @return the sampler.
+         */
+        public ContinuousSampler getSampler() {
+            return sampler;
+        }
+
+        /** Instantiates sampler. */
+        @Setup
+        public void setup() {
+            final RandomSource randomSource = 
RandomSource.valueOf(randomSourceName);
+            final UniformRandomProvider rng = randomSource.create();
+            sampler = createSampler(type, rng);
+        }
+    }
+
+    /**
      * The samplers to use for testing the ziggurat method with sequential 
sample generation.
      * Defines the RandomSource and the sampler type.
      *
@@ -367,7 +373,7 @@ public class ZigguratSamplerPerformance {
      * chosen using both sets of results.
      */
     @State(Scope.Benchmark)
-    public static class SequentialSources {
+    public static class SequentialSources extends Sources {
         /**
          * RNG providers.
          *
@@ -382,19 +388,6 @@ public class ZigguratSamplerPerformance {
         })
         private String randomSourceName;
 
-        /** The sampler type. */
-        @Param({// Production versions
-                GAUSSIAN_128, GAUSSIAN_256, MOD_GAUSSIAN, MOD_EXPONENTIAL,
-                // Experimental Marsaglia exponential ziggurat sampler
-                EXPONENTIAL,
-                // Experimental McFarland Gaussian ziggurat samplers
-                MOD_GAUSSIAN2, MOD_GAUSSIAN_SIMPLE_OVERHANGS, 
MOD_GAUSSIAN_INLINING,
-                MOD_GAUSSIAN_INLINING_SIMPLE_OVERHANGS, MOD_GAUSSIAN_INT_MAP, 
MOD_GAUSSIAN_512,
-                // Experimental McFarland Gaussian ziggurat samplers
-                MOD_EXPONENTIAL_LOOP, MOD_EXPONENTIAL_LOOP2,
-                MOD_EXPONENTIAL_RECURSION, MOD_EXPONENTIAL_INT_MAP, 
MOD_EXPONENTIAL_512})
-        private String type;
-
         /** The size. */
         @Param({"1", "2", "4", "8", "16", "32", "64"})
         private int size;
@@ -414,8 +407,8 @@ public class ZigguratSamplerPerformance {
         public void setup() {
             final RandomSource randomSource = 
RandomSource.valueOf(randomSourceName);
             final UniformRandomProvider rng = randomSource.create();
-            final ContinuousSampler s = Sources.createSampler(type, rng);
-            sampler = createSampler(size, s);
+            final ContinuousSampler s = createSampler(type, rng);
+            sampler = createSequentialSampler(size, s);
         }
 
         /**
@@ -425,7 +418,7 @@ public class ZigguratSamplerPerformance {
          * @param s the sampler to create the samples
          * @return the sampler
          */
-        private static ContinuousSampler createSampler(int size, 
ContinuousSampler s) {
+        private static ContinuousSampler createSequentialSampler(int size, 
ContinuousSampler s) {
             // Create size samples
             switch (size) {
             case 1:
@@ -3681,7 +3674,7 @@ public class ZigguratSamplerPerformance {
      * @return the sample value
      */
     @Benchmark
-    public double sample(Sources sources) {
+    public double sample(SingleSources sources) {
         return sources.getSampler().sample();
     }
 

Reply via email to