public static void ComparePerformanceOfCachedAndOnTheFlySegmentStateCalculators( string logFilePath, int repetitions, BitMatrix board, Matrix <Cell> cellMatrix, Matrix <SegmentState> vertSegStateMatrix, Matrix <SegmentState> horizSegStateMatrix, Matrix <bool> boolMatrix) { // Cache based segment state calculator: CacheBasedSegmentStateCalculator cacheSegStateCalculator = new CacheBasedSegmentStateCalculator(horizSegStateMatrix, vertSegStateMatrix); PerformanceTestHelper.TimeActionWithArgument(logFilePath, "Calculate all segments using cache calculator", repetitions, Tuple.Create(board.BottomRight, cacheSegStateCalculator), CalculateSegmentStatesUsingCache); // Calculation based segment state calculator: CalculationBasedSegmentStateCalculator calcSegStateCalculator = new CalculationBasedSegmentStateCalculator(board); PerformanceTestHelper.TimeActionWithArgument(logFilePath, "Calculate all segments using direct BitMatrix-based calculator", repetitions, Tuple.Create(board.BottomRight, calcSegStateCalculator), CalculateSegmentStatesUsingCalculationBasedCalculator); // Bool Matrix based on the fly segment state calculator: OnTheFlyBoolMatrixBasedSegmentStateCalculator boolMatrixBasedSegStateCalculator = new OnTheFlyBoolMatrixBasedSegmentStateCalculator(boolMatrix); PerformanceTestHelper.TimeActionWithArgument(logFilePath, "Calculate all segments using direct bool matrix based calculator", repetitions, Tuple.Create(boolMatrix.BottomRight, boolMatrixBasedSegStateCalculator), CalculateSegmentStatesUsingOnTheFlyBoolBoolBasedCalculator); CellMatrixBasedSegmentStateCalculator cellCacheSegStateCalculator = new CellMatrixBasedSegmentStateCalculator(board, cellMatrix); PerformanceTestHelper.TimeActionWithArgument(logFilePath, "Calculate all segments using cell matrix-based cache calculator", repetitions, Tuple.Create(board.BottomRight, cellCacheSegStateCalculator), CalculateSegmentStatesUsingCellCacheBasedCalculator); /* Compare segment state calculation times over random points for cached and calculated segment state calculators, * to make sure the cache calculator is not just benefiting from memory cache effects due to the sequence of points: */ Core.Point[] randomPoints = DataGenerator.GenerateRandomPoints(board.TopLeft, board.BottomRight, 10000); // Cache based segment state calculator: PerformanceTestHelper.TimeActionWithArgument(logFilePath, "Calculate segments on random points using cache calculator", repetitions, Tuple.Create(randomPoints, cacheSegStateCalculator), CalculateSegmentStatesOnRandomPointsUsingCache); PerformanceTestHelper.TimeActionWithArgument(logFilePath, "Calculate segments on random points using cell matrix-based cache calculator", repetitions, Tuple.Create(randomPoints, cellCacheSegStateCalculator), CalculateSegmentStatesOnRandomPointsUsingCache); // Calculation based segment state calculator: PerformanceTestHelper.TimeActionWithArgument(logFilePath, "Calculate segments on random points using on the fly calculator", repetitions, Tuple.Create(randomPoints, calcSegStateCalculator), CalculateSegmentStatesOnRandomPointsUsingCalculationBasedCalculator); // Bool Matrix based on the fly segment state calculator: PerformanceTestHelper.TimeActionWithArgument(logFilePath, "Calculate segments on random points using on the fly bool matrix based calculator", repetitions, Tuple.Create(randomPoints, boolMatrixBasedSegStateCalculator), CalculateSegmentStatesOnRandomPointsUsingOnTheFlyBoolBoolBasedCalculator); }
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); }