Example #1
0
        /// <summary>
        /// Cache GetAll.
        /// </summary>
        private void GetAll(BenchmarkState state)
        {
            var idx  = BenchmarkUtils.GetRandomInt(Dataset - DatasetBatchSize);
            var keys = Enumerable.Range(idx, DatasetBatchSize);

            Cache.GetAll(keys);
        }
        /// <summary>
        /// Cache put.
        /// </summary>
        private void PutTx(BenchmarkState state)
        {
            int idx = BenchmarkUtils.GetRandomInt(Dataset);

            using (var tx = Node.GetTransactions().TxStart(TransactionConcurrency.Pessimistic,
                                                           TransactionIsolation.RepeatableRead))
            {
                _cache.Put(idx, Emps[idx]);

                tx.Commit();
            }
        }
Example #3
0
        /// <summary>
        /// Cache put.
        /// </summary>
        private void PutTx(BenchmarkState state)
        {
            int idx = BenchmarkUtils.GetRandomInt(Dataset);

            using (var tx = Node.GetTransactions().TxStart(TransactionConcurrency.Pessimistic,
                TransactionIsolation.RepeatableRead))
            {
                _cache.Put(idx, Emps[idx]);

                tx.Commit();
            }
        }
        /// <summary>
        /// Write address.
        /// </summary>
        /// <param name="state">State.</param>
        private void ReadTestModel(BenchmarkState state)
        {
            //var model = _marsh.StartUnmarshal(_mem.GetStream()).ReadObject<TestModel>();

            //if (model.Byte != _model.Byte)
            //    throw new InvalidOperationException();

            var model = _marsh.StartUnmarshal(_mem.GetStream()).ReadObject <Address>();

            if (model.FlatNumber != _address.FlatNumber)
            {
                throw new InvalidOperationException();
            }
        }
        /// <summary>
        /// Write address.
        /// </summary>
        /// <param name="state">State.</param>
        private void WriteAddress(BenchmarkState state)
        {
            var mem = _memMgr.Allocate();

            try
            {
                var stream = mem.GetStream();

                _marsh.StartMarshal(stream).Write(_address);
            }
            finally
            {
                mem.Release();
            }
        }
Example #6
0
    public static void CommandBenchmark(CommandArg[] args)
    {
        string note = "";

        if (args != null && args.Length >= 1)
        {
            note = string.Join(" ", from a in args select a.String);
        }

        var state = new BenchmarkState(note);

        CurrState      = state;
        CurrSceneIndex = 0;
        GameBuilderSceneController scenes = FindObjectOfType <GameBuilderSceneController>();

        SceneLoadStartTime = Time.realtimeSinceStartup;
        scenes.RestartAndLoad(System.IO.Path.Combine(Application.streamingAssetsPath, "ExampleGames", "Internal", BenchmarkVoosFiles[0]));
    }
Example #7
0
            private static bool IsStateWithExternals(BenchmarkState state)
            {
                switch (state)
                {
                case BenchmarkState.WithoutExternals:
                case BenchmarkState.WithoutAnimatorsWithoutExternals:
                case BenchmarkState.WithoutMeshesWithoutExternals:
                    return(false);

                case BenchmarkState.WithExternals:
                case BenchmarkState.WithoutAnimatorsWithExternals:
                case BenchmarkState.WithoutMeshesWithExternals:
                    return(true);

                case BenchmarkState.Ant:
                case BenchmarkState.Externals:
                case BenchmarkState.Last:
                default:
                    throw new InvalidOperationException();
                }
            }
Example #8
0
    // Update is called once per frame
    void Update()
    {
        switch (state)
        {
        // General idle states
        case BenchmarkState.Idle:
            // This state intentionally left blank
            break;

        // Run once to set up the benchmark. NOTE: Avoiding const folding chance w/ system random to choose specific seeded random.
        case BenchmarkState.Begin:
            benchmarks = new List <Benchmark>();
            System.Random sysRand = new System.Random();     // Derived by default from system clock. Can be different per system, but it's effectively random.
            rand = new Utils.WichmannRng(BENCH_GENERAL_SEED);
            display.ClearAll();

            // Prevent const folding w/ sys rand, use wichmannRNG for controlled rand in testing
            double sysDouble = sysRand.NextDouble() * 2;
            Debug.Log($"Sys double: {sysDouble}");
            if (sysDouble >= 1)
            {
                benchmarks.Add(new Benchmark_Int(rand, "I ops"));
                benchmarks.Add(new Benchmark_Int(rand, "I ops"));
                benchmarks.Add(new Benchmark_Long(rand, "L ops"));
                benchmarks.Add(new Benchmark_Int(rand, "I ops"));
                benchmarks.Add(new Benchmark_Long(rand, "L ops"));
                benchmarks.Add(new Benchmark_Long(rand, "L ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B D ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B D ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B F ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B D ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B F ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B F ops"));
            }
            else
            {
                benchmarks.Add(new Benchmark_Double(rand, "1B F ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B F ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B D ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B D ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B F ops"));
                benchmarks.Add(new Benchmark_Double(rand, "1B D ops"));
                benchmarks.Add(new Benchmark_Long(rand, "L ops"));
                benchmarks.Add(new Benchmark_Long(rand, "L ops"));
                benchmarks.Add(new Benchmark_Int(rand, "I ops"));
                benchmarks.Add(new Benchmark_Int(rand, "I ops"));
                benchmarks.Add(new Benchmark_Long(rand, "L ops"));
                benchmarks.Add(new Benchmark_Int(rand, "I ops"));
            }


            currentBench     = benchmarks[currentBenchIndex];
            run.interactable = false;
            state            = BenchmarkState.Init;
            break;



        case BenchmarkState.Init:
            // Some casual resets. pre-calc/format as much as possible.
            state         = BenchmarkState.Execute;
            preformat     = $"%, {currentBenchIndex}/{benchmarks.Count}";
            progress.text = "";

            // Force a blocking clear for the GC to level the playing field
            System.GC.Collect(generation: 0, mode: GCCollectionMode.Forced, blocking: true);

            // Begin recording right before coroutine start. *nothing* after this but coroutine start.
            startTime = System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            // At start of execute
            StartCoroutine(currentBench.Perform(
                               () =>
            {
                // End time before *anything* else.
                endTime = System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                state   = BenchmarkState.Display;
            },
                               (percent) =>
            {
                // Preformatted for simple join. String.Join is fastest w/o string builder apparently(?) - minimize perf overhead
                // https://dotnetcoretutorials.com/2020/02/06/performance-of-string-concatenation-in-c/
                progress.text = String.Join("", percent, preformat);
            }
                               ));
            break;

        case BenchmarkState.Execute:
            // This state intentionally left blank
            break;

        case BenchmarkState.Display:
            long diff = endTime - startTime;
            display.AddItem(currentBench.Name, $"{diff}ms");
            progress.text = "";

            if (++currentBenchIndex < benchmarks.Count)
            {
                currentBench = benchmarks[currentBenchIndex];
                state        = BenchmarkState.Init;
            }
            else
            {
                state = BenchmarkState.Finished;
            }
            break;



        // General end state
        case BenchmarkState.Finished:
            run.interactable  = true;
            currentBench      = null;
            currentBenchIndex = 0;
            state             = BenchmarkState.Idle;
            break;
        }
    }
Example #9
0
        /// <summary>
        /// Cache get.
        /// </summary>
        private void Get(BenchmarkState state)
        {
            var idx = BenchmarkUtils.GetRandomInt(Dataset);

            _cache.Get(idx);
        }
        /// <summary>
        /// Write address.
        /// </summary>
        /// <param name="state">State.</param>
        private void WriteAddress(BenchmarkState state)
        {
            var mem = _memMgr.Allocate();

            try
            {
                var stream = mem.GetStream();

                _marsh.StartMarshal(stream).Write(_address);
            }
            finally
            {
                mem.Release();
            }
        }
        /// <summary>
        /// Write address.
        /// </summary>
        /// <param name="state">State.</param>
        private void ReadTestModel(BenchmarkState state)
        {
            //var model = _marsh.StartUnmarshal(_mem.GetStream()).ReadObject<TestModel>();

            //if (model.Byte != _model.Byte)
            //    throw new InvalidOperationException();

            var model = _marsh.StartUnmarshal(_mem.GetStream()).ReadObject<Address>();

            if (model.FlatNumber != _address.FlatNumber)
                throw new InvalidOperationException();

        }
Example #12
0
        /// <summary>
        /// Cache put.
        /// </summary>
        private void Put(BenchmarkState state)
        {
            int idx = BenchmarkUtils.GetRandomInt(Dataset);

            _cache.Put(idx, Emps[idx]);
        }
Example #13
0
 /// <summary>
 /// Executes task.
 /// </summary>
 private void ExecuteEmptyTask(BenchmarkState state)
 {
     Node.GetCompute().Execute(new MyEmptyTask(), "zzzz");
 }
Example #14
0
 // Start is called before the first frame update
 void Start()
 {
     progress.text = "";
     run.onClick.AddListener(() => state = BenchmarkState.Begin);
 }
Example #15
0
 /// <summary>
 /// Executes closure.
 /// </summary>
 private void ExecuteClosureTask(BenchmarkState state)
 {
     Node.GetCompute().Call(new MyClosure("zzzz"));
 }
        /// <summary>
        /// Cache getAsync.
        /// </summary>
        private void GetAsync(BenchmarkState state)
        {
            int idx = BenchmarkUtils.GetRandomInt(Dataset);

            _cache.GetAsync(idx).Wait();
        }
        /// <summary>
        /// Cache putAsync.
        /// </summary>
        private void PutAsync(BenchmarkState state)
        {
            int idx = BenchmarkUtils.GetRandomInt(Dataset);

            _cache.PutAsync(idx, Emps[idx]).Wait();
        }
Example #18
0
    IEnumerator BenchmarkRoutine()
    {
        float loadToStart = Time.realtimeSinceStartup - SceneLoadStartTime;

        UnityEngine.Profiling.Profiler.enabled   = false;
        SaveLoadController.SuppressLegacyWarning = true;

        // Let the framerate run free..
        QualitySettings.vSyncCount  = 0;
        Application.targetFrameRate = -1;

        // Hitches..
        autosaves.SetPaused(true);

        CheckGlobals();

        while (!voosEngine.GetIsRunning())
        {
            yield return(null);
        }

        float loadToVoos = Time.realtimeSinceStartup - SceneLoadStartTime;

        // Make sure we want for all terrain chunks too..
        while (!terrain.IsSettledForPerfMeasurement())
        {
            yield return(new WaitForSecondsRealtime(0.5f));
        }

        float loadToTerrain = Time.realtimeSinceStartup - SceneLoadStartTime;

        // Let it settle down a bit..
        yield return(new WaitForSecondsRealtime(2f));

        CheckGlobals();

        // Now collect some frame times.
        const int numSamples = 200;

        long[]  sampleTicks            = new long[numSamples];
        float[] voosUpdateSampleMillis = new float[numSamples];

        SD.Stopwatch watch = new SD.Stopwatch();
        // Don't run until we start our first frame.
        watch.Stop();

        int currSample = 0;

        voosEngine.onVoosUpdateTiming += millis =>
        {
            if (watch.IsRunning)
            {
                voosUpdateSampleMillis[currSample] = millis;
            }
        };

        while (true)
        {
            CheckGlobals();
            yield return(new WaitForEndOfFrame());

            if (watch.IsRunning)
            {
                // Just finished recording a sample!
                watch.Stop();
                sampleTicks[currSample] = watch.ElapsedTicks;
                currSample++;
                if (currSample >= numSamples)
                {
                    // All done!
                    break;
                }
            }
            // Start next sample.
            watch.Restart();
        }

        // Sanity check voos.
        foreach (float voosMs in voosUpdateSampleMillis)
        {
            Debug.Assert(voosMs > 0);
        }

        float averageMs = TicksToMillis(sampleTicks.Sum()) / numSamples;

        float averageVoosMs = voosUpdateSampleMillis.Sum() / numSamples;

        // Update state file and kick off the next one..
        BenchmarkState state = CurrState;

        Array.Sort(sampleTicks);
        var res = new BenchmarkState.SceneResult
        {
            voosFile        = BenchmarkVoosFiles[CurrSceneIndex],
            avgFrameMs      = averageMs,
            avgVoosUpdateMs = averageVoosMs,
            percentile90    = TicksToMillis(sampleTicks.AtFractionalPosition(0.90f)),
            percentile95    = TicksToMillis(sampleTicks.AtFractionalPosition(0.95f)),
            percentile99    = TicksToMillis(sampleTicks.AtFractionalPosition(0.99f)),
            loadToStart     = loadToStart,
            loadToTerrain   = loadToTerrain,
            loadToVoos      = loadToVoos,
            actorBytes      = networking.GetVoosInitBytes().Length,
            terrainBytes    = terrain.SerializeTerrainV2().Length
        };

        state.results = state.results ?? new BenchmarkState.SceneResult[0];
        state.results = state.results.ExpensiveWith(res);
        CurrSceneIndex++;

        Util.Log($"OK finished benchmark for scene {res.voosFile}. avgFrameMs={res.avgFrameMs} avgVoosUpdateMs={res.avgVoosUpdateMs}");

        CheckGlobals();

        if (CurrSceneIndex >= BenchmarkVoosFiles.Length)
        {
            string outDir = Path.Combine((Application.isEditor ? "editor-" : "release-") + "benchmark-results", System.Net.Dns.GetHostName());
            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }
            // We're done! Save to file.
            string outPath = Path.Combine(outDir, System.DateTime.Now.ToString("yyyyMMddTHHmm") + ".json");
            File.WriteAllText(outPath, JsonUtility.ToJson(CurrState, true));
            CurrState = null;

            FindObjectOfType <GameBuilderSceneController>().LoadSplashScreen();
        }
        else
        {
            GameBuilderSceneController scenes = FindObjectOfType <GameBuilderSceneController>();
            SceneLoadStartTime = Time.realtimeSinceStartup;
            scenes.RestartAndLoad(System.IO.Path.Combine(Application.streamingAssetsPath, "ExampleGames", "Internal", BenchmarkVoosFiles[CurrSceneIndex]));
        }
    }
        /// <summary>
        /// Cache get.
        /// </summary>
        private void Get(BenchmarkState state)
        {
            var idx = BenchmarkUtils.GetRandomInt(Dataset);

            _cache.Get(idx);
        }
        /// <summary>
        /// Cache getAsync.
        /// </summary>
        private void GetAsync(BenchmarkState state)
        {
            int idx = BenchmarkUtils.GetRandomInt(Dataset);

            _cache.GetAsync(idx).Wait();
        }