/// <summary> /// Initializes a new instance of the <see cref="GcdAlgorithmWithTimePerformance"/> class. /// </summary> /// <param name="algorithm">Selected gcd algorithm.</param> /// <param name="timeCalculator">Util for calculating time.</param> public GcdAlgorithmWithTimePerformance(IGcdAlgorithm algorithm, ITimeCalculator timeCalculator) { algorithm.CheckOnNull(); timeCalculator.CheckOnNull(); this.timeCalculator = timeCalculator; this.algorithm = algorithm; }
/// <summary> /// Calculates gcd and time of algorithm's execution. /// </summary> /// <param name="gcdAlgorithm">Gcd algorithm.</param> /// <param name="first">First number.</param> /// <param name="second">Second number.</param> /// <param name="timeCalculator">Util for time calculation.</param> /// <param name="timeForCalculations">Result time of algorithm's execution.</param> /// <returns></returns> public static int CalculateGcdWithTime(this IGcdAlgorithm gcdAlgorithm, int first, int second, ITimeCalculator timeCalculator, out long timeForCalculations) { gcdAlgorithm.CheckOnNull(); timeCalculator.CheckOnNull(); timeCalculator.Start(); int gcd = gcdAlgorithm.Calculate(first, second); timeCalculator.Stop(); timeForCalculations = timeCalculator.TimeInMilliseconds; return(gcd); }