Exemplo n.º 1
0
        static void Benchmark(IMultiply multiply)
        {
            var testFramework = new TestMultiply();

            var watch = new Stopwatch();

            watch.Start();

            var testNo = 0;

            for (var i = 0; i < RunNum; i++)
            {
                testNo = testFramework.CheckSolution(multiply);
            }

            watch.Stop();

            Console.WriteLine();
            Console.BackgroundColor = ConsoleColor.Yellow;
            Console.WriteLine($"Checked {multiply.GetType().FullName}");
            Console.BackgroundColor = ConsoleColor.Green;
            Console.WriteLine(
                $"Did {testNo} checks times {RunNum} in" +
                $" {watch.ElapsedTicks} ticks or {watch.ElapsedMilliseconds} ms.");

            Console.WriteLine();
            Console.BackgroundColor = ConsoleColor.White;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Measures the time of the algorithm.
        /// Calls Square method of MatrixFacade instance.
        /// </summary>
        /// <param name="mul">Passed algorithm for matrix multiply.</param>
        public override void Square(IMultiply mul)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            _facade.Square(mul);
            stopwatch.Stop();
            Time = stopwatch.ElapsedMilliseconds;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Measures the time of the algorithm.
        /// Calls Multiply method of MatrixFacade instance.
        /// </summary>
        /// <param name="other">Other matrix to be multiplied to this.</param>
        /// <param name="mul">Passed algorithm for matrix multiply.</param>
        /// <returns>New matrix that equals to substraction of this and other matrixes.</returns>
        public override Matrix Multiply(Matrix other, IMultiply mul)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var ret = _facade.Multiply(other, mul);

            stopwatch.Stop();
            Time = stopwatch.ElapsedMilliseconds;
            return(ret);
        }
Exemplo n.º 4
0
        public int CheckSolution(IMultiply multiply)
        {
            AssertEqual(multiply.Multiply(1, 2), 2);
            AssertEqual(multiply.Multiply(1, -2), -2);
            AssertEqual(multiply.Multiply(-1, -2), 2);
            AssertEqual(multiply.Multiply(-1, 2), -2);
            AssertEqual(multiply.Multiply(10, 5), 50);
            AssertEqual(multiply.Multiply(-10, 5), -50);
            AssertEqual(multiply.Multiply(10, -5), -50);
            AssertEqual(multiply.Multiply(-10, -5), 50);

            return(8); // number of tests (AssertEqual) performed
        }
Exemplo n.º 5
0
        private void squareButton2_Click(object sender, EventArgs e)
        {
            TakeBoxes(_right.Matrix, _rightBoxes);
            IMultiply algorithm = squareBox2.SelectedIndex switch
            {
                0 => new NativeMultiply(),
                1 => new LibraryMultiply(),
                _ => null
            };

            _right.Square(algorithm);
            RefreshBoxes(_right.Matrix, _rightBoxes);
            if (_right is TimeDecorator timeDecorator)
            {
                timeLabel.Text = timeDecorator.Time + " ms";
            }
        }
Exemplo n.º 6
0
        private void multiplyButton_Click(object sender, EventArgs e)
        {
            TakeBoxes(_left.Matrix, _leftBoxes);
            TakeBoxes(_right.Matrix, _rightBoxes);
            IMultiply algorithm = mulBox1.SelectedIndex switch
            {
                0 => new NativeMultiply(),
                1 => new LibraryMultiply(),
                _ => null
            };

            _result = _left.Multiply(_right.Matrix, algorithm);
            RefreshResultBoxes();
            if (_left is TimeDecorator timeDecorator)
            {
                timeLabel.Text = timeDecorator.Time + " ms";
            }
        }
 public void Setup()
 {
     _algorithm = new LibraryMultiply();
 }
Exemplo n.º 8
0
 public NumberCollection()
 {
     this.listOfNumbers = new List <int>();
     this.mulStrategy   = new MulBy2();
 }
Exemplo n.º 9
0
 public NumberCollection(List list)
 {
     listOfNumbers = new List <int>();
     mulStrategy   = new MulBy2();
 }
Exemplo n.º 10
0
 /// <summary>
 /// Square matrix using passed algorithm.
 /// </summary>
 /// <param name="mul">Passed algorithm for matrix multiply.</param>
 public virtual void Square(IMultiply mul)
 {
     _history.Backup();
     Matrix.MultiplyAlgorithm = mul;
     Matrix = Matrix.Square();
 }
Exemplo n.º 11
0
 /// <summary>
 /// Multiply other this to other using passed algorithm.
 /// </summary>
 /// <param name="other">Other matrix to be multiplied to this.</param>
 /// <param name="mul">Passed algorithm for matrix multiply.</param>
 /// <returns>New matrix that equals to substraction of this and other matrixes.</returns>
 public virtual Matrix Multiply(Matrix other, IMultiply mul)
 {
     Matrix.MultiplyAlgorithm = mul;
     other.MultiplyAlgorithm  = mul;
     return(Matrix * other);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Calls Square method of MatrixFacade instance.
 /// </summary>
 /// <param name="mul">Passed algorithm for matrix multiply.</param>
 public virtual void Square(IMultiply mul)
 {
     _facade.Square(mul);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Calls Multiply method of MatrixFacade instance.
 /// </summary>
 /// <param name="other">Other matrix to be multiplied to this.</param>
 /// <param name="mul">Passed algorithm for matrix multiply.</param>
 /// <returns>New matrix that equals to substraction of this and other matrixes.</returns>
 public virtual Matrix Multiply(Matrix other, IMultiply mul)
 {
     return(_facade.Multiply(other, mul));
 }
Exemplo n.º 14
0
 public void Setup()
 {
     _algorithm = new NativeMultiply();
 }