001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.commons.rng.examples.jmh;
019
020import org.apache.commons.rng.simple.RandomSource;
021import org.openjdk.jmh.annotations.Param;
022import org.openjdk.jmh.annotations.Scope;
023import org.openjdk.jmh.annotations.Setup;
024import org.openjdk.jmh.annotations.State;
025
026/**
027 * A benchmark state that can retrieve the various {@link RandomSource} values.
028 *
029 * <p>The state will include only those that do not require additional constructor arguments.</p>
030 */
031@State(Scope.Benchmark)
032public class RandomSourceValues {
033    /**
034     * RNG providers. This list is maintained in the order of the {@link RandomSource} enum.
035     *
036     * <p>Include only those that do not require additional constructor arguments.</p>
037     *
038     * <p>Note: JMH does support using an Enum for the {@code @Param} annotation. However
039     * the default set will encompass all the enum values, including those that require
040     * additional constructor arguments. So this list is maintained manually.</p>
041     */
042    @Param({"JDK",
043            "WELL_512_A",
044            "WELL_1024_A",
045            "WELL_19937_A",
046            "WELL_19937_C",
047            "WELL_44497_A",
048            "WELL_44497_B",
049            "MT",
050            "ISAAC",
051            "SPLIT_MIX_64",
052            "XOR_SHIFT_1024_S",
053            "TWO_CMRES",
054            "MT_64",
055            "MWC_256",
056            "KISS",
057            "XOR_SHIFT_1024_S_PHI",
058            "XO_RO_SHI_RO_64_S",
059            "XO_RO_SHI_RO_64_SS",
060            "XO_SHI_RO_128_PLUS",
061            "XO_SHI_RO_128_SS",
062            "XO_RO_SHI_RO_128_PLUS",
063            "XO_RO_SHI_RO_128_SS",
064            "XO_SHI_RO_256_PLUS",
065            "XO_SHI_RO_256_SS",
066            "XO_SHI_RO_512_PLUS",
067            "XO_SHI_RO_512_SS",
068            "PCG_XSH_RR_32",
069            "PCG_XSH_RS_32",
070            "PCG_RXS_M_XS_64",
071            "PCG_MCG_XSH_RR_32",
072            "PCG_MCG_XSH_RS_32",
073            "MSWS",
074            "SFC_32",
075            "SFC_64",
076            "JSF_32",
077            "JSF_64",
078            "XO_SHI_RO_128_PP",
079            "XO_RO_SHI_RO_128_PP",
080            "XO_SHI_RO_256_PP",
081            "XO_SHI_RO_512_PP",
082            "XO_RO_SHI_RO_1024_PP",
083            "XO_RO_SHI_RO_1024_S",
084            "XO_RO_SHI_RO_1024_SS",
085            "PCG_XSH_RR_32_OS",
086            "PCG_XSH_RS_32_OS",
087            "PCG_RXS_M_XS_64_OS",
088            "L64_X128_SS",
089            "L64_X128_MIX",
090            "L64_X256_MIX",
091            "L64_X1024_MIX",
092            "L128_X128_MIX",
093            "L128_X256_MIX",
094            "L128_X1024_MIX",
095            "L32_X64_MIX"})
096    private String randomSourceName;
097
098    /** The RandomSource. */
099    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}