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; }
/// <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; }
/// <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); }
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 }
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"; } }
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(); }
public NumberCollection() { this.listOfNumbers = new List <int>(); this.mulStrategy = new MulBy2(); }
public NumberCollection(List list) { listOfNumbers = new List <int>(); mulStrategy = new MulBy2(); }
/// <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(); }
/// <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); }
/// <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); }
/// <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)); }
public void Setup() { _algorithm = new NativeMultiply(); }