Beispiel #1
0
        public void WriteMatrixToFile <T>(MyMatrix <T> matrix, string fileName) where T : new()
        {
            var formattedMatrix = MyMatrixFormatter.GetFormattedMatrix(matrix);

            WriteToFile(fileName, formattedMatrix, matrix.Rows);
        }
        public void MatrixMulMatrixTest(int testCount)
        {
            // ---------------------------------------------------------
            // fraction
            // ---------------------------------------------------------
            _time = new TimeSpan();
            var frResult = new MyMatrix <Fraction>(1, 1);

            for (var i = 0; i < testCount; i++)
            {
                var frA = new MyMatrix <Fraction>(SfrA);
                var frB = new MyMatrix <Fraction>(SfrB);
                var frC = new MyMatrix <Fraction>(SfrC);

                _stopwatch.Reset();
                _stopwatch.Start();
                frResult = frA * (frB * frC);
                _stopwatch.Stop();
                _time += _stopwatch.Elapsed;
            }

            _handler.WriteToFileWithTimespan(
                IO.PrefixFraction + IO.ResultAbc,
                MyMatrixFormatter.GetFormattedMatrix(frResult),
                CurrentMatrixSize,
                _time.TotalMilliseconds / testCount);


            // ---------------------------------------------------------
            // float
            // ---------------------------------------------------------
            _time = new TimeSpan();
            var fResult = new MyMatrix <float>(0, 0);

            for (var i = 0; i < testCount; i++)
            {
                var fA = new MyMatrix <float>(SfA);
                var fB = new MyMatrix <float>(SfB);
                var fC = new MyMatrix <float>(SfC);

                _stopwatch.Reset();
                _stopwatch.Start();
                fResult = fA * (fB * fC);
                _stopwatch.Stop();
                _time += _stopwatch.Elapsed;
            }

            _handler.WriteToFileWithTimespan(
                IO.PrefixFloat + IO.ResultAbc,
                MyMatrixFormatter.GetFormattedMatrix(fResult),
                CurrentMatrixSize,
                _time.TotalMilliseconds / testCount);

            // ---------------------------------------------------------
            // double
            // ---------------------------------------------------------
            _time = new TimeSpan();
            var dResult = new MyMatrix <double>(0, 0);

            for (var i = 0; i < testCount; i++)
            {
                var dA = new MyMatrix <double>(SdA);
                var dB = new MyMatrix <double>(SdB);
                var dC = new MyMatrix <double>(SdC);

                _stopwatch.Reset();
                _stopwatch.Start();
                dResult = dA * (dB * dC);
                _stopwatch.Stop();
                _time += _stopwatch.Elapsed;
            }

            _handler.WriteToFileWithTimespan(
                IO.PrefixDouble + IO.ResultAbc,
                MyMatrixFormatter.GetFormattedMatrix(dResult),
                CurrentMatrixSize,
                _time.TotalMilliseconds / testCount);
        }