Esempio n. 1
0
 public override IEnumerable <StateVariable> GetState()
 {
     return(new[] {
         new StateVariable
         {
             Name = "RandomType",
             Value = RandomType.ToString(),
             Type = StateVariable.StateType.Input
         },
         new StateVariable
         {
             Name = "From",
             Value = From,
             Type = StateVariable.StateType.Input
         },
         new StateVariable
         {
             Name = "To",
             Value = To,
             Type = StateVariable.StateType.Input
         },
         new StateVariable
         {
             Name = "Length",
             Value = Length,
             Type = StateVariable.StateType.Input
         },
         new StateVariable
         {
             Name = "Result",
             Value = Result,
             Type = StateVariable.StateType.Output
         }
     });
 }
    void SetRandomType(RandomType next)
    {
        _randomType          = next;
        _randomTypeText.text = next.ToString();
        for (int i = 0; i < ThreadCount; i++)
        {
            switch (_randomType)
            {
            case RandomType.XorShift128: _randoms[i] = new XorShift128(i); break;

            case RandomType.XorShift64: _randoms[i] = new XorShift64(i); break;

            case RandomType.XorShift32: _randoms[i] = new XorShift32(i); break;

            case RandomType.Mwc32: _randoms[i] = new Mwc32(i); break;

            case RandomType.Mwc64: _randoms[i] = new Mwc64(i); break;

            case RandomType.Standard: _randoms[i] = new Standard(i); break;

            case RandomType.BadLcg: _randoms[i] = new BadLcg(i); break;

            case RandomType.PopularLcg: _randoms[i] = new PopularLcg(i); break;
            }
        }
    }
    void BenchmarkSub()
    {
        const int N    = 1000 * 1000 * 100; // 1億
        var       t0   = Time.realtimeSinceStartup;
        int       sum  = 0;                 // 結果を何かに使わないと最適化で消されそうなので用意
        var       rand = _randoms[0];

        for (int i = 0; i < N; i++)
        {
            sum += rand.Next();
        }
        var t1 = Time.realtimeSinceStartup;

        Debug.Log(_randomType.ToString() + " " + (t1 - t0) + " sum:" + sum);
    }
Esempio n. 4
0
    void OnGUI()
    {
        GUILayout.BeginHorizontal();
        GUILayout.Label("RandomType");
        if (GUILayout.Button(_randomType.ToString()))
        {
            Clear();
            // タイプ変更
            RandomType next = RandomType.None;
            switch (_randomType)
            {
            case RandomType.XorShift128: next = RandomType.XorShift64; break;

            case RandomType.XorShift64: next = RandomType.XorShift32; break;

            case RandomType.XorShift32: next = RandomType.Mwc32; break;

            case RandomType.Mwc32: next = RandomType.Mwc64; break;

            case RandomType.Mwc64: next = RandomType.Standard; break;

            case RandomType.Standard: next = RandomType.BadLcg; break;

            case RandomType.BadLcg: next = RandomType.PopularLcg; break;

            case RandomType.PopularLcg: next = RandomType.MinStd; break;

            case RandomType.MinStd: next = RandomType.XorShift128; break;
            }
            SetRandomType(next);
            if (_testType == TestType.Gorilla)
            {
                StartCoroutine(CoGorillaTest());
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("TestType");
        if (GUILayout.Button(_testType.ToString()))
        {
            Clear();
            // タイプ変更
            switch (_testType)
            {
            case TestType.Fill: _testType = TestType.Gorilla; break;

            case TestType.Gorilla: _testType = TestType.Fill; break;
            }
            if (_testType == TestType.Gorilla)
            {
                StartCoroutine(CoGorillaTest());
            }
        }
        GUILayout.EndHorizontal();

        if (GUILayout.Button("Benchmark"))
        {
            StartCoroutine(CoBenchmark());
        }
        if (_benchmarkResult != null)
        {
            GUILayout.Label(_benchmarkResult);
        }
    }