Beispiel #1
0
        public void Multiplication(string resultFile, int maxDigits)
        {
            double previousRatio = 0;

            Console.WriteLine("Testing multiplication...");
            Console.WriteLine("# of Digits\t\tAvg Time (ns)\t\tDoubling Ratio");

            for (int i = 1; i <= maxDigits; i += i)
            {
                for (int trial = 0; trial < numberOfTrials; trial++)
                {
                    MyBigIntegers randomNum1 = new MyBigIntegers(NumberGenerator(i));
                    MyBigIntegers randomNum2 = new MyBigIntegers(NumberGenerator(i));

                    stopwatch.Restart();
                    randomNum1.Times(randomNum2.value);
                    stopwatch.Stop();
                    nanoSecs += stopwatch.Elapsed.TotalMilliseconds * 1000000;
                }

                double averageTrialTime = nanoSecs / numberOfTrials;
                if (previousRatio > 0)
                {
                    doubleRatio = averageTrialTime / previousRatio;
                }
                previousRatio = averageTrialTime;
                Console.WriteLine("{0,-10}\t{1,16}\t\t{2,10:N2}", i, averageTrialTime, doubleRatio);

                using (StreamWriter outputFile = new StreamWriter(Path.Combine(resultsFolderPath, resultFile), true))
                {
                    outputFile.WriteLine("{0,-10} {1,16} {2,10:N2}", i, averageTrialTime, doubleRatio);
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            MyBigIntegers bigInt1 = new MyBigIntegers("123123123123123123");
            MyBigIntegers bigInt2 = new MyBigIntegers("321321321321321321");

            bigInt1.PrintString();
            bigInt2.PrintString();

            Console.WriteLine(bigInt1.Plus(bigInt2.value));
            Console.WriteLine(bigInt1.Times(bigInt2.value));
        }