Beispiel #1
0
        public static void TestRecoveryBlockPrime()
        {
            long          maxSearch   = 100;
            PrimeSearcher primeSearch = new PrimeSearcher();

            Console.WriteLine("\n\n\nWithout recovery blocks: ");
            primeSearch.Search(maxSearch);
            primeSearch.PrintResults();
            Console.WriteLine("");

            primeSearch = new PrimeSearcher();
            Func <PrimeSearcher, long, List <long> > algoFail1 = PrimeSearcher.SearchStatic;
            Func <long, List <long> > algoFail2 = primeSearch.SearchFail;
            Func <long, List <long> > algo1     = primeSearch.Search;
            Func <long, List <long> > algo2     = PrimeSearcher.SearchStatic;
            Func <bool> checkPrimes             = primeSearch.CheckPrimes;

            RecoveryBlock reco = new RecoveryBlock(checkPrimes);

            reco.AddAlgorithm(algoFail1);
            reco.AddAlgorithm(algoFail2);
            reco.AddAlgorithm(algo1);
            reco.AddAlgorithm(algo2);
            reco.AddAlgorithm((Func <long, List <long> >)primeSearch.SearchUnoptimized); //Just a different way to add the algorithm.

            List <long> primes2 = reco.Run <List <long>, PrimeSearcher, long>(maxSearch);

            Console.WriteLine("Recovery block run result:\n" + string.Join(",", primes2.ToArray()) + "\n\n");
        }
Beispiel #2
0
        public static void TestCheckpoint()
        {
            PrimeSearcher primes = new PrimeSearcher();
            Checkpoint<PrimeSearcher> checkpoint = new Checkpoint<PrimeSearcher>();
            try
            {
                primes = checkpoint.Load();
            }
            catch (Exception) { }
            for (long i = 0; i < 100; i++)
            {
                Stopwatch timer = Stopwatch.StartNew();
                primes.Search(10);
                if (timer.ElapsedMilliseconds > 1000)
                {
                    checkpoint.Save(primes);
                    timer.Restart();
                }
            }
            checkpoint.Save(primes);

            primes.PrintResults();
            TestCheckpoint jk = new TestCheckpoint();
            Checkpoint<TestCheckpoint> checkpoint2 = new Checkpoint<TestCheckpoint>();
        }
Beispiel #3
0
        public static void TestCheckpoint()
        {
            PrimeSearcher primes = new PrimeSearcher();
            Checkpoint <PrimeSearcher> checkpoint = new Checkpoint <PrimeSearcher>();

            try
            {
                primes = checkpoint.Load();
            }
            catch (Exception) { }
            for (long i = 0; i < 100; i++)
            {
                Stopwatch timer = Stopwatch.StartNew();
                primes.Search(10);
                if (timer.ElapsedMilliseconds > 1000)
                {
                    checkpoint.Save(primes);
                    timer.Restart();
                }
            }
            checkpoint.Save(primes);

            primes.PrintResults();
            TestCheckpoint jk = new TestCheckpoint();
            Checkpoint <TestCheckpoint> checkpoint2 = new Checkpoint <TestCheckpoint>();
        }
Beispiel #4
0
        public static void TestRecoveryBlockPrime()
        {
            long maxSearch = 100;
            PrimeSearcher primeSearch = new PrimeSearcher();

            Console.WriteLine("\n\n\nWithout recovery blocks: ");
            primeSearch.Search(maxSearch);
            primeSearch.PrintResults();
            Console.WriteLine("");

            primeSearch = new PrimeSearcher();
            Func<PrimeSearcher, long, List<long>> algoFail1 = PrimeSearcher.SearchStatic;
            Func<long, List<long>> algoFail2 = primeSearch.SearchFail;
            Func<long, List<long>> algo1 = primeSearch.Search;
            Func<long, List<long>> algo2 = PrimeSearcher.SearchStatic;
            Func<bool> checkPrimes = primeSearch.CheckPrimes;

            RecoveryBlock reco = new RecoveryBlock(checkPrimes);

            reco.AddAlgorithm(algoFail1);
            reco.AddAlgorithm(algoFail2);
            reco.AddAlgorithm(algo1);
            reco.AddAlgorithm(algo2);
            reco.AddAlgorithm((Func<long, List<long>>)primeSearch.SearchUnoptimized); //Just a different way to add the algorithm.

            List<long> primes2 = reco.Run<List<long>, PrimeSearcher, long>(maxSearch);
            Console.WriteLine("Recovery block run result:\n" + string.Join(",", primes2.ToArray()) + "\n\n");
        }
 public static List<long> SearchStatic(PrimeSearcher primer, long endAmount)
 {
     return primer.Search(endAmount);
 }
 public static List<long> SearchStatic(long endNumber)
 {
     PrimeSearcher primer = new PrimeSearcher();
     return primer.Search(endNumber);
 }
 public static List <long> SearchStatic(PrimeSearcher primer, long endAmount)
 {
     return(primer.Search(endAmount));
 }
        public static List <long> SearchStatic(long endNumber)
        {
            PrimeSearcher primer = new PrimeSearcher();

            return(primer.Search(endNumber));
        }