Exemplo n.º 1
0
 private static void ProcessDataSet(IDigitCountAlgorithm algorithm)
 {
     foreach (int radix in Radixes)
     {
         foreach (int number in Numbers)
         {
             algorithm.GetDigitCount(number, radix);
         }
     }
 }
Exemplo n.º 2
0
        private void RunOneAlgorithmBatch(IDigitCountAlgorithm algorithm)
        {
            Stopwatch timer = GetTimerForAlgorithm(algorithm);

            timer.Start();

            for (int i = 0; i < BatchSize; i++)
            {
                ProcessDataSet(algorithm);
            }

            timer.Stop();
        }
Exemplo n.º 3
0
        private Stopwatch GetTimerForAlgorithm(IDigitCountAlgorithm algorithm)
        {
            string typeName = algorithm.GetType().Name;

            if (_timers.TryGetValue(typeName, out Stopwatch timer))
            {
                return(timer);
            }

            timer = new Stopwatch();
            _timers.Add(typeName, timer);

            return(timer);
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Creates a new instance of <see cref="XMath" /> class with desired set of algorithms optionally specified.
 /// </summary>
 /// <param name="digitCountAlgorithm">
 ///     An instance of <see cref="IDigitCountAlgorithm" /> interface for counting digits in a
 ///     number.
 /// </param>
 public XMath(IDigitCountAlgorithm digitCountAlgorithm = null)
 {
     _digitCountAlgorithm = digitCountAlgorithm ?? new IterativeMultiplicationByRadixAlgorithm();
 }