Exemplo n.º 1
0
        public static void RunCalc(ProfileSet set)
        {
            var runner     = ProfileTools.GetSet(set);
            var reportTime = set switch
            {
                ProfileSet.Primitives => 1_000_000,
                ProfileSet.Middle => 80000,
                ProfileSet.Complex => 10000,
                ProfileSet.All => 2000,
                _ => throw new ArgumentOutOfRangeException(nameof(set), set, null)
            };

            var calculateBench = new ProfileCalculateSet();

            for (int i = 0; i < 3; i++)
            {
                runner(calculateBench);
            }

            int measurementsCount = 0;
            int historyCount      = 10;

            var calcStopWatch = new Stopwatch();
            var calcHistory   = new LinkedList <double>();


            for (int iterations = 1; !Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape; iterations++)
            {
                calcStopWatch.Start();
                runner(calculateBench);
                calcStopWatch.Stop();

                if (iterations >= reportTime)
                {
                    measurementsCount++;

                    calcHistory.AddAndTruncate(calcStopWatch.Elapsed.TotalMilliseconds, historyCount);

                    var total           = calcStopWatch.Elapsed;
                    var buildAndRunTime = calcStopWatch.Elapsed;

                    calcStopWatch.Reset();

                    PrintHeader("CALC", set, measurementsCount, total);
                    PrintResults("calculate", buildAndRunTime, calcHistory, iterations);
                    PrintFooter();

                    iterations = 1;
                }
            }
        }
Exemplo n.º 2
0
        public static void RunAll(ProfileSet set)
        {
            var runner     = ProfileTools.GetSet(set);
            var reportTime = set switch
            {
                ProfileSet.Primitives => 4000,
                ProfileSet.Middle => 1500,
                ProfileSet.Complex => 500,
                ProfileSet.All => 500,
                _ => throw new ArgumentOutOfRangeException(nameof(set), set, null)
            };


            var buildBench     = new ProfileBuildAllSet();
            var parseBench     = new ProfileParserSet();
            var updateBench    = new ProfileUpdateSet();
            var calculateBench = new ProfileCalculateSet();

            for (int i = 0; i < 3; i++)
            {
                runner(parseBench);
                runner(buildBench);
                runner(updateBench);
                runner(calculateBench);
            }

            int measurementsCount = 0;
            int historyCount      = 10;

            var parseStopWatch = new Stopwatch();
            var parseHistory   = new LinkedList <double>();

            var buildStopWatch = new Stopwatch();
            var buildHistory   = new LinkedList <double>();

            var interpritateHistory = new LinkedList <double>();

            var updateStopWatch = new Stopwatch();
            var updateHistory   = new LinkedList <double>();

            var calcStopWatch = new Stopwatch();
            var calcHistory   = new LinkedList <double>();


            for (int iterations = 1; !Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape; iterations++)
            {
                parseStopWatch.Start();
                runner(parseBench);
                parseStopWatch.Stop();

                buildStopWatch.Start();
                runner(buildBench);
                buildStopWatch.Stop();

                updateStopWatch.Start();
                runner(updateBench);
                updateStopWatch.Stop();

                calcStopWatch.Start();
                runner(calculateBench);
                calcStopWatch.Stop();

                if (iterations >= reportTime)
                {
                    measurementsCount++;

                    parseHistory.AddAndTruncate(parseStopWatch.Elapsed.TotalMilliseconds, historyCount);
                    buildHistory.AddAndTruncate(buildStopWatch.Elapsed.TotalMilliseconds, historyCount);

                    interpritateHistory.AddAndTruncate(buildStopWatch.Elapsed.TotalMilliseconds -
                                                       parseStopWatch.Elapsed.TotalMilliseconds, historyCount);

                    updateHistory.AddAndTruncate(updateStopWatch.Elapsed.TotalMilliseconds, historyCount);
                    calcHistory.AddAndTruncate(calcStopWatch.Elapsed.TotalMilliseconds, historyCount);

                    var total = parseStopWatch.Elapsed + buildStopWatch.Elapsed + updateStopWatch.Elapsed +
                                calcStopWatch.Elapsed;
                    var buildAndRunTime = buildStopWatch.Elapsed + calcStopWatch.Elapsed;

                    parseStopWatch.Reset();
                    buildStopWatch.Reset();
                    updateStopWatch.Reset();
                    calcStopWatch.Reset();

                    PrintHeader("everything", set, measurementsCount, total);
                    PrintResults("parse    ", buildAndRunTime, parseHistory, iterations);
                    PrintResults("interprt ", buildAndRunTime, interpritateHistory, iterations);
                    PrintResults("calculate", buildAndRunTime, calcHistory, iterations);
                    PrintResults("update   ", buildAndRunTime, updateHistory, iterations);
                    PrintFooter();

                    iterations = 1;
                }
            }
        }