Esempio n. 1
0
 static void checkDuration(PrimaryNumberChecker checker, Stopwatch watch, string strategy, int start, int finish)
 {
     watch.Restart(); watch.Start();
     checker.getPrimaryNumbers(start, finish);
     watch.Stop();
     Console.WriteLine($"Finding all primes within [{start}, {finish}] using {strategy} took {watch.Elapsed.ToString()}");
 }
Esempio n. 2
0
        static void printPrimesInRange(int start, int finish)
        {
            PrimaryNumberChecker checker = new PrimaryNumberChecker(new EratosthenesSieveStrategy(finish));

            Console.WriteLine($"Primary numbers in the range: [{start}, {finish}]");
            IList <int> primaryNumbers = checker.getPrimaryNumbers(start, finish);

            foreach (int number in primaryNumbers)
            {
                Console.WriteLine(number);
            }
        }
Esempio n. 3
0
        static void compareMethods(int multiplicator)
        {
            Stopwatch watch = new Stopwatch();
            int       start = 10 * multiplicator, finish = 100 * multiplicator;
            IPrimaryCheckingStrategy divisionStrat = new DivisionStrategy(),
                                     eratosthenesStrat = new EratosthenesSieveStrategy(finish);

            PrimaryNumberChecker checker = new PrimaryNumberChecker(eratosthenesStrat);

            checkDuration(checker, watch, eratosthenesStrat.GetType().ToString(), start, finish);
            checker.setStrategy(divisionStrat);
            checkDuration(checker, watch, divisionStrat.GetType().ToString(), start, finish);
        }