You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2019/04/11 08:58:51 UTC
[commons-rng] 01/02: Removed redundant JMH benchmarks from examples.
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
commit eb234aaa6dd559baf71a551487b4b66078f81ed5
Author: aherbert <ah...@apache.org>
AuthorDate: Thu Apr 11 09:58:02 2019 +0100
Removed redundant JMH benchmarks from examples.
---
.../rng/examples/jmh/ConstructionPerformance.java | 4 +-
.../rng/examples/jmh/GenerationPerformance.java | 150 -------------
.../jmh/distribution/SamplersPerformance.java | 232 ---------------------
3 files changed, 2 insertions(+), 384 deletions(-)
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/ConstructionPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/ConstructionPerformance.java
index c560bcb..7da3c95 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/ConstructionPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/ConstructionPerformance.java
@@ -69,8 +69,8 @@ import org.apache.commons.rng.simple.internal.ProviderBuilder.RandomSourceIntern
* Executes a benchmark to compare the speed of construction of random number providers.
*
* <p>Note that random number providers are created and then used. Thus the construction time must
- * be analysed together with the run time performance benchmark (see
- * {@link GenerationPerformance}).
+ * be analysed together with the run time performance benchmark (see for example
+ * {@link NextIntGenerationPerformance} and {@link NextLongGenerationPerformance}).
*
* <pre>
* [Total time] = [Construction time] + [Run time]
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/GenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/GenerationPerformance.java
deleted file mode 100644
index 741c510..0000000
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/GenerationPerformance.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * 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.rng.examples.jmh;
-
-import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.annotations.Warmup;
-import org.openjdk.jmh.annotations.Measurement;
-import org.openjdk.jmh.annotations.State;
-import org.openjdk.jmh.annotations.Fork;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.Param;
-import org.openjdk.jmh.annotations.OutputTimeUnit;
-import org.openjdk.jmh.infra.Blackhole;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Executes benchmark to compare the speed of generation of random numbers
- * from the various source providers.
- *
- * @deprecated Replaced by benchmarks for each method, for example
- * {@link NextDoubleGenerationPerformance}.
- */
-@BenchmarkMode(Mode.AverageTime)
-@OutputTimeUnit(TimeUnit.MICROSECONDS)
-@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
-@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
-@State(Scope.Benchmark)
-@Fork(value = 1, jvmArgs = {"-server", "-Xms128M", "-Xmx128M"})
-@Deprecated
-public class GenerationPerformance {
- /**
- * Number of random values to generate.
- */
- @Param({"1", "100", "10000", "1000000"})
- private int numValues;
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void nextBoolean(RandomSources sources,
- Blackhole bh) {
- for (int i = 0; i < numValues; i++) {
- bh.consume(sources.getGenerator().nextBoolean());
- }
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void nextInt(RandomSources sources,
- Blackhole bh) {
- for (int i = 0; i < numValues; i++) {
- bh.consume(sources.getGenerator().nextInt());
- }
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void nextIntN(RandomSources sources,
- Blackhole bh) {
- final int n = 10;
- for (int i = 0; i < numValues; i++) {
- bh.consume(sources.getGenerator().nextInt(n));
- }
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void nextLong(RandomSources sources,
- Blackhole bh) {
- for (int i = 0; i < numValues; i++) {
- bh.consume(sources.getGenerator().nextLong());
- }
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void nextLongN(RandomSources sources,
- Blackhole bh) {
- final long n = 2L * Integer.MAX_VALUE;
- for (int i = 0; i < numValues; i++) {
- bh.consume(sources.getGenerator().nextLong(n));
- }
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void nextFloat(RandomSources sources,
- Blackhole bh) {
- for (int i = 0; i < numValues; i++) {
- bh.consume(sources.getGenerator().nextFloat());
- }
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void nextDouble(RandomSources sources,
- Blackhole bh) {
- for (int i = 0; i < numValues; i++) {
- bh.consume(sources.getGenerator().nextDouble());
- }
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void nextBytes(RandomSources sources,
- Blackhole bh) {
- final byte[] result = new byte[numValues];
- sources.getGenerator().nextBytes(result);
- bh.consume(result);
- }
-}
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/SamplersPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/SamplersPerformance.java
deleted file mode 100644
index 1a5344e..0000000
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/SamplersPerformance.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * 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.rng.examples.jmh.distribution;
-
-import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.annotations.Warmup;
-import org.openjdk.jmh.annotations.Measurement;
-import org.openjdk.jmh.annotations.State;
-import org.openjdk.jmh.annotations.Fork;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.OutputTimeUnit;
-import org.openjdk.jmh.infra.Blackhole;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.commons.rng.examples.jmh.RandomSources;
-import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
-import org.apache.commons.rng.sampling.distribution.DiscreteSampler;
-import org.apache.commons.rng.sampling.distribution.BoxMullerNormalizedGaussianSampler;
-import org.apache.commons.rng.sampling.distribution.MarsagliaNormalizedGaussianSampler;
-import org.apache.commons.rng.sampling.distribution.ZigguratNormalizedGaussianSampler;
-import org.apache.commons.rng.sampling.distribution.AhrensDieterExponentialSampler;
-import org.apache.commons.rng.sampling.distribution.AhrensDieterMarsagliaTsangGammaSampler;
-import org.apache.commons.rng.sampling.distribution.LogNormalSampler;
-import org.apache.commons.rng.sampling.distribution.ChengBetaSampler;
-import org.apache.commons.rng.sampling.distribution.ContinuousUniformSampler;
-import org.apache.commons.rng.sampling.distribution.DiscreteUniformSampler;
-import org.apache.commons.rng.sampling.distribution.GeometricSampler;
-import org.apache.commons.rng.sampling.distribution.RejectionInversionZipfSampler;
-import org.apache.commons.rng.sampling.distribution.PoissonSampler;
-
-/**
- * Executes benchmark to compare the speed of generation of random numbers
- * from the various source providers.
- *
- * @deprecated Replaced by {@link ContinuousSamplersPerformance} and
- * {@link DiscreteSamplersPerformance}.
- */
-@BenchmarkMode(Mode.AverageTime)
-@OutputTimeUnit(TimeUnit.MICROSECONDS)
-@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
-@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
-@State(Scope.Benchmark)
-@Fork(value = 1, jvmArgs = {"-server", "-Xms128M", "-Xmx128M"})
-@Deprecated
-public class SamplersPerformance {
- /** Number of samples per run. */
- private static final int NUM_SAMPLES = 10000000;
-
- /**
- * Exercises a continuous sampler.
- *
- * @param sampler Sampler.
- * @param bh Data sink.
- */
- private static void runSample(ContinuousSampler sampler,
- Blackhole bh) {
- for (int i = 0; i < NUM_SAMPLES; i++) {
- bh.consume(sampler.sample());
- }
- }
-
- /**
- * Exercises a discrete sampler.
- *
- * @param sampler Sampler.
- * @param bh Data sink.
- */
- private static void runSample(DiscreteSampler sampler,
- Blackhole bh) {
- for (int i = 0; i < NUM_SAMPLES; i++) {
- bh.consume(sampler.sample());
- }
- }
-
- // Benchmarks methods below.
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runBoxMullerNormalizedGaussianSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new BoxMullerNormalizedGaussianSampler(sources.getGenerator()), bh);
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runMarsagliaNormalizedGaussianSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new MarsagliaNormalizedGaussianSampler(sources.getGenerator()), bh);
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runZigguratNormalizedGaussianSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new ZigguratNormalizedGaussianSampler(sources.getGenerator()), bh);
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runAhrensDieterExponentialSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new AhrensDieterExponentialSampler(sources.getGenerator(), 4.56), bh);
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runAhrensDieterMarsagliaTsangGammaSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new AhrensDieterMarsagliaTsangGammaSampler(sources.getGenerator(), 9.8, 0.76), bh);
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runBoxMullerLogNormalSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new LogNormalSampler(new BoxMullerNormalizedGaussianSampler(sources.getGenerator()), 12.3, 4.6), bh);
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runMarsagliaLogNormalSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new LogNormalSampler(new MarsagliaNormalizedGaussianSampler(sources.getGenerator()), 12.3, 4.6), bh);
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runZigguratLogNormalSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new LogNormalSampler(new ZigguratNormalizedGaussianSampler(sources.getGenerator()), 12.3, 4.6), bh);
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runChengBetaSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new ChengBetaSampler(sources.getGenerator(), 0.45, 6.7), bh);
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runContinuousUniformSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new ContinuousUniformSampler(sources.getGenerator(), 123.4, 5678.9), bh);
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runDiscreteUniformSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new DiscreteUniformSampler(sources.getGenerator(), -98, 76), bh);
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runRejectionInversionZipfSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new RejectionInversionZipfSampler(sources.getGenerator(), 43, 2.1), bh);
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runPoissonSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new PoissonSampler(sources.getGenerator(), 8.9), bh);
- }
-
- /**
- * @param sources Source of randomness.
- * @param bh Data sink.
- */
- //@org.openjdk.jmh.annotations.Benchmark
- public void runGeometricSampler(RandomSources sources,
- Blackhole bh) {
- runSample(new GeometricSampler(sources.getGenerator(), 0.21), bh);
- }
-}