public static void TestBitMatrix(string logFilePath, int repetitions)
        {
            string bitMatrixType = "BitMatrix using an int array";
            string title;

            title = String.Format("Construct and populate a {0}", bitMatrixType);
            BitMatrix bm = PerformanceTestHelper.TimeFunction(logFilePath, title, repetitions, ConstructBitMatrix);

            title = String.Format("Read a {0}", bitMatrixType);
            PerformanceTestHelper.TimeActionWithArgument(logFilePath, title, repetitions, bm, ReadBitMatrix);

            title = String.Format("Clone a {0}", bitMatrixType);
            PerformanceTestHelper.TimeActionWithArgument(logFilePath, title, repetitions, bm, CloneBitMatrix);
        }
예제 #2
0
        public void TestDistanceCalculator(string logFilePath, int repetitions, int smallRepetitions)
        {
            SegStateCalculator = new CacheBasedSegmentStateCalculator(HorizSegmentStateMatrix, VertSegmentStateMatrix);
            TankEdgeMatrix     = PerformanceTestHelper.TimeFunction(
                logFilePath, "Calculate tank edge matrix using TankEdgeCalculator", repetitions,
                CalculateTankOuterEdgeMatrix);

            MobileState tankState1 = new MobileState(new Point(20, 6), Direction.UP, isActive: true);

            DistancesFromTank1 = PerformanceTestHelper.TimeFunctionWithArgument(logFilePath, "Test Distance Calculator for tank 1",
                                                                                smallRepetitions, tankState1, CalculateDistancesForTank);

            MobileState tankState2 = new MobileState(new Point(56, 6), Direction.UP, isActive: true);

            DistancesFromTank2 = PerformanceTestHelper.TimeFunctionWithArgument(logFilePath, "Test Distance Calculator for tank 2",
                                                                                smallRepetitions, tankState2, CalculateDistancesForTank);
        }
        public void Test(int repetitions, int smallRepetitions, string logFilePath)
        {
            VerticalSegmentStateMatrix
                = PerformanceTestHelper.TimeFunction(logFilePath,
                                                     "Test calculation of vertical segment state matrix directly from the BitMatrix",
                                                     repetitions, GetVerticalSegmentStateMatrix);

            // Save image for vertical segment state matrix:
            Bitmap segStateBitmap = ImageGenerator.GenerateBoardImage(Board);

            ImageGenerator.DrawSegmentMatrixOverlay(segStateBitmap, Board, VerticalSegmentStateMatrix, Axis.Vertical);
            string segmentMatrixFilePath = @"c:\Competitions\EntelectChallenge2013\temp\VertSegmentMatrix.bmp";

            segStateBitmap.Save(segmentMatrixFilePath, ImageFormat.Bmp);

            HorizontalSegStateMatrix
                = PerformanceTestHelper.TimeFunction(logFilePath,
                                                     "Test calculation of horizontal segment state matrix directly from the BitMatrix",
                                                     repetitions, GetHorizontalSegmentStateMatrix);

            // Save image for horizontal segment state matrix:
            segStateBitmap = ImageGenerator.GenerateBoardImage(Board);
            ImageGenerator.DrawSegmentMatrixOverlay(segStateBitmap, Board, HorizontalSegStateMatrix, Axis.Horizontal);
            segmentMatrixFilePath = @"c:\Competitions\EntelectChallenge2013\temp\HorizSegmentMatrix.bmp";
            segStateBitmap.Save(segmentMatrixFilePath, ImageFormat.Bmp);

            ImageGenerator.DrawSegmentMatrixOverlay(segStateBitmap, Board, VerticalSegmentStateMatrix, Axis.Vertical);
            segmentMatrixFilePath = @"c:\Competitions\EntelectChallenge2013\temp\BiDiSegmentMatrix.bmp";
            segStateBitmap.Save(segmentMatrixFilePath, ImageFormat.Bmp);

            // Test calculation caches:
            PerformanceTestHelper.TimeAction(logFilePath,
                                             "Time cell calculator on challenge board 1", smallRepetitions,
                                             PerformCellCalculation);
            CellMatrix = PerformanceTestHelper.TimeFunction(logFilePath,
                                                            "Time cell and segment calculator on challenge board 1",
                                                            smallRepetitions, PerformCellAndSegmentCalculation);

            // Repeat segment stage calculations using implementation based on pre-calculated cell and segment calculations:
            VerticalSegmentStateMatrix = PerformanceTestHelper.TimeFunctionWithArgument(logFilePath,
                                                                                        "Test calculation of vertical segment state matrix using a cell matrix",
                                                                                        repetitions, Axis.Vertical, GetSegmentStateMatrixUsingCellMatrix);

            // Save image for vertical segment state matrix:
            segStateBitmap = ImageGenerator.GenerateBoardImage(Board);
            ImageGenerator.DrawSegmentMatrixOverlay(segStateBitmap, Board, VerticalSegmentStateMatrix, Axis.Vertical);
            segmentMatrixFilePath = @"c:\Competitions\EntelectChallenge2013\temp\VertSegmentMatrixUsingCellMatrix.bmp";
            segStateBitmap.Save(segmentMatrixFilePath, ImageFormat.Bmp);

            HorizontalSegStateMatrix = PerformanceTestHelper.TimeFunctionWithArgument(logFilePath,
                                                                                      "Test calculation of horizontal segment state matrix using a cell matrix",
                                                                                      repetitions, Axis.Horizontal, GetSegmentStateMatrixUsingCellMatrix);

            // Repeat segment state calculation using Segment matrix calculated from the Cell matrix:
            Matrix <Segment> vertSegmentMatrix = SegmentCalculator.GetSegmentMatrix(CellMatrix, Board, Axis.Vertical);

            VerticalSegmentStateMatrix = PerformanceTestHelper.TimeFunctionWithArgument(logFilePath,
                                                                                        "Test calculation of vertical segment state matrix using a segment matrix",
                                                                                        repetitions, Tuple.Create(vertSegmentMatrix, Board),
                                                                                        (tuple) => SegmentCalculator.GetBoardSegmentStateMatrixFromSegmentMatrix(tuple.Item1, tuple.Item2));

            Matrix <Segment> horizSegmentMatrix = SegmentCalculator.GetSegmentMatrix(CellMatrix, Board, Axis.Horizontal);

            HorizontalSegStateMatrix = PerformanceTestHelper.TimeFunctionWithArgument(logFilePath,
                                                                                      "Test calculation of vertical segment state matrix using a segment matrix",
                                                                                      repetitions, Tuple.Create(horizSegmentMatrix, Board),
                                                                                      (tuple) => SegmentCalculator.GetBoardSegmentStateMatrixFromSegmentMatrix(tuple.Item1, tuple.Item2));

            // Save image for horizontal segment state matrix:
            segStateBitmap = ImageGenerator.GenerateBoardImage(Board);
            ImageGenerator.DrawSegmentMatrixOverlay(segStateBitmap, Board, HorizontalSegStateMatrix, Axis.Horizontal);
            segmentMatrixFilePath = @"c:\Competitions\EntelectChallenge2013\temp\HorizSegmentMatrixUsingCellMatrix.bmp";
            segStateBitmap.Save(segmentMatrixFilePath, ImageFormat.Bmp);

            ImageGenerator.DrawSegmentMatrixOverlay(segStateBitmap, Board, VerticalSegmentStateMatrix, Axis.Vertical);
            segmentMatrixFilePath = @"c:\Competitions\EntelectChallenge2013\temp\BiDiSegmentMatrixUsingCellMatrix.bmp";
            segStateBitmap.Save(segmentMatrixFilePath, ImageFormat.Bmp);
        }