コード例 #1
0
ファイル: Benchmark.cs プロジェクト: knot3/knot3-code
        static void Main(string[] args)
        {
            Action test = null;
            string description = null;
            TimeStatistics timeStatistics = new TimeStatistics ();

            // setUp ();
            PrintTimerProperties ();

            //foreach (int length in ExtremeKnots.SquareKnot_TestLengths) {
            /*
            description = "Knoten-Erzeugen: Knoten mit 100 Kanten, 100 WH:";
            test = () => ExtremeKnots.CreateSquareKnot (100, "");
            timeStatistics = StopTime (test, 100, timeStatistics);
            PrintTimeStatistics (timeStatistics, description);
            */
            // }
            /*
            int my_length = 100;

            description = "Knoten-Erzeugen: Knoten mit " + my_length + " Kanten, " + my_length + " WH:";
            test = () => ExtremeKnots.CreateSquareKnot (my_length, "");
            timeStatistics = StopTime (test, my_length, timeStatistics);
            PrintTimeStatistics (timeStatistics, description);
            */

            description = "Knoten-Laden: Knoten mit 10000 Kanten, 100 WH:";
            test = () => ExtremeKnots.LoadSquareKnot (SystemInfo.SavegameDirectory + "\\SquareKnot10000.knot");
            timeStatistics = StopTime (test, 100, timeStatistics);
            PrintTimeStatistics (timeStatistics, description);

            /*
            Knot knot = KnotGenerator.generateSquareKnot (10000 / 4, "SquareKnot10000");
            KnotFileIO knotFileIO = new KnotFileIO ();
            knotFileIO.Save (knot);
            */

            System.Console.Write (ExtremeKnots.knot);
        }
コード例 #2
0
ファイル: Benchmark.cs プロジェクト: knot3/knot3-code
        // todo noch in MS und S ...
        public static void PrintTimeStatistics(TimeStatistics timeStatistics, string description)
        {
            long nanosToMilis = 1000L * 1000L;
            long milisToSecs = 1000L;

            // Langsamste Zeit ...
            long maxNanos = timeStatistics.slowest;
            long maxMilis = maxNanos / nanosToMilis;
            long maxSecs = maxMilis / milisToSecs;

            // Schnellste Zeit ...
            long minNanos = timeStatistics.fastest;
            long minMilis = minNanos / nanosToMilis;
            long minSecs = minMilis / milisToSecs;

            // Mittlere Zeit ...
            long avgNanos = timeStatistics.average;
            long avgMilis = avgNanos / nanosToMilis;
            long avgSecs = avgMilis / milisToSecs;

            // Ausreißer ...
            long outNanos = timeStatistics.outlier;
            long outMilis = outNanos / nanosToMilis;
            long outSecs = outMilis / milisToSecs;

            Console.Write (
                // "Name: "
                description + "\n"
                + "max = " + maxNanos + " NS >= " + maxMilis + " MS >= " + maxSecs + " S\n"
                + "min = " + minNanos + " NS >= " + minMilis + " MS >= " + minSecs + " S\n"
                + "avg = " + avgNanos + " NS >= " + avgMilis + " MS >= " + avgSecs + " S\n"
                + "out = " + outNanos + " NS >= " + outMilis + " MS >= " + outSecs + " S\n"
            );
        }
コード例 #3
0
ファイル: Benchmark.cs プロジェクト: knot3/knot3-code
        public static TimeStatistics StopTime(Action action, int numberOfPasses, TimeStatistics timeStatistics)
        {
            Stopwatch stopwatch = new Stopwatch ();
            long nsPerTick = (1000L * 1000L * 1000L) / Stopwatch.Frequency;

            timeStatistics.slowest = long.MinValue;
            timeStatistics.fastest = long.MaxValue;
            timeStatistics.average = 0;
            // todo: timeStatistics.name = ...

            numberOfPasses++;

            for (int countedPass = 0; countedPass < numberOfPasses; countedPass++) {
                stopwatch.Reset ();
                stopwatch.Start ();
                action ();
                stopwatch.Stop ();

                if (countedPass == 0) {
                    timeStatistics.outlier = stopwatch.ElapsedTicks * nsPerTick;
                    numberOfPasses--;
                    continue;
                }

                if (stopwatch.ElapsedTicks < 0) {
                    numberOfPasses++;
                    continue;
                }

                if (stopwatch.ElapsedTicks > timeStatistics.slowest) {
                    timeStatistics.slowest = stopwatch.ElapsedTicks;
                }
                else if (stopwatch.ElapsedTicks < timeStatistics.fastest) {
                    timeStatistics.fastest = stopwatch.ElapsedTicks;
                }

                // no overflow testing ...

                timeStatistics.average = timeStatistics.average + stopwatch.ElapsedTicks;

                // no cache pollution ...
            }

            timeStatistics.average = timeStatistics.average / numberOfPasses;

            // todo
            timeStatistics.slowest = timeStatistics.slowest * nsPerTick;
            timeStatistics.fastest = timeStatistics.fastest * nsPerTick;
            timeStatistics.average = timeStatistics.average * nsPerTick;

            return timeStatistics;
        }