View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.rng.examples.jmh;
19  
20  import org.apache.commons.rng.simple.RandomSource;
21  import org.openjdk.jmh.annotations.Param;
22  import org.openjdk.jmh.annotations.Scope;
23  import org.openjdk.jmh.annotations.Setup;
24  import org.openjdk.jmh.annotations.State;
25  
26  /**
27   * A benchmark state that can retrieve the various {@link RandomSource} values.
28   *
29   * <p>The state will include only those that do not require additional constructor arguments.</p>
30   */
31  @State(Scope.Benchmark)
32  public class RandomSourceValues {
33      /**
34       * RNG providers. This list is maintained in the order of the {@link RandomSource} enum.
35       *
36       * <p>Include only those that do not require additional constructor arguments.</p>
37       *
38       * <p>Note: JMH does support using an Enum for the {@code @Param} annotation. However
39       * the default set will encompass all the enum values, including those that require
40       * additional constructor arguments. So this list is maintained manually.</p>
41       */
42      @Param({"JDK",
43              "WELL_512_A",
44              "WELL_1024_A",
45              "WELL_19937_A",
46              "WELL_19937_C",
47              "WELL_44497_A",
48              "WELL_44497_B",
49              "MT",
50              "ISAAC",
51              "SPLIT_MIX_64",
52              "XOR_SHIFT_1024_S",
53              "TWO_CMRES",
54              "MT_64",
55              "MWC_256",
56              "KISS",
57              "XOR_SHIFT_1024_S_PHI",
58              "XO_RO_SHI_RO_64_S",
59              "XO_RO_SHI_RO_64_SS",
60              "XO_SHI_RO_128_PLUS",
61              "XO_SHI_RO_128_SS",
62              "XO_RO_SHI_RO_128_PLUS",
63              "XO_RO_SHI_RO_128_SS",
64              "XO_SHI_RO_256_PLUS",
65              "XO_SHI_RO_256_SS",
66              "XO_SHI_RO_512_PLUS",
67              "XO_SHI_RO_512_SS",
68              "PCG_XSH_RR_32",
69              "PCG_XSH_RS_32",
70              "PCG_RXS_M_XS_64",
71              "PCG_MCG_XSH_RR_32",
72              "PCG_MCG_XSH_RS_32",
73              "MSWS",
74              "SFC_32",
75              "SFC_64",
76              "JSF_32",
77              "JSF_64",
78              "XO_SHI_RO_128_PP",
79              "XO_RO_SHI_RO_128_PP",
80              "XO_SHI_RO_256_PP",
81              "XO_SHI_RO_512_PP",
82              "XO_RO_SHI_RO_1024_PP",
83              "XO_RO_SHI_RO_1024_S",
84              "XO_RO_SHI_RO_1024_SS",
85              "PCG_XSH_RR_32_OS",
86              "PCG_XSH_RS_32_OS",
87              "PCG_RXS_M_XS_64_OS",
88              "L64_X128_SS",
89              "L64_X128_MIX",
90              "L64_X256_MIX",
91              "L64_X1024_MIX",
92              "L128_X128_MIX",
93              "L128_X256_MIX",
94              "L128_X1024_MIX",
95              "L32_X64_MIX"})
96      private String randomSourceName;
97  
98      /** The RandomSource. */
99      private RandomSource randomSource;
100 
101     /**
102      * Gets the random source.
103      *
104      * @return the random source
105      */
106     public RandomSource getRandomSource() {
107         return randomSource;
108     }
109 
110     /**
111      * Look-up the {@link RandomSource} from the name.
112      */
113     @Setup
114     public void setup() {
115         randomSource = RandomSource.valueOf(randomSourceName);
116     }
117 }