示例#1
0
        static void Main(string[] args)
        {
            for (int i = 250; true; i += i)
            {
                var time = DoublingTest.TimeTrial(i);
                Console.WriteLine($"{i}\t{time}");
            }

            List <string> randomNumbers = new List <string>();

            if (!File.Exists("./1000.txt"))
            {
                int    upperLimit = 1000;
                Random a          = new Random();
                for (int i = 0; i < upperLimit; i++)
                {
                    randomNumbers.Add(a.Next(-1000, 1000).ToString());
                }
                File.WriteAllLines("./1000.txt", randomNumbers);
            }

            var inputNumbers = File.ReadAllLines("./1000.txt").Select(int.Parse).ToArray();

            AlgStopWatch watch      = new AlgStopWatch();
            var          totalCount = ThreeSumCalculator.Count(inputNumbers);
            var          notOfTicks = watch.ElapsedTime();

            Console.WriteLine($"Total count = {totalCount} and took {notOfTicks} seconds");
            Console.ReadLine();
        }
示例#2
0
        public static double TimeTrial(int noOfInput)
        {
            int max = 1000000;

            int[] input = new int[noOfInput];

            Random ran = new Random();

            for (int i = 0; i < noOfInput; i++)
            {
                input[i] = ran.Next(-max, max);
            }

            AlgStopWatch timer = new AlgStopWatch();

            ThreeSumCalculator.Count(input);
            return(timer.ElapsedTime());
        }