コード例 #1
0
        static void Main(string[] args)
        {
            foreach (var arg in args)
            {
                int max;
                if (int.TryParse(arg, out max))
                {
                    CountCountUpSequence(max);
                    CountLinkedList(max);
                    CountList(max);
                }
            }

            var smallCountUpSequence = new CountUpSequence(10);

            WriteLine("Count up sequence elements:");
            foreach (var i in smallCountUpSequence)
            {
                WriteLine(i);
            }
        }
コード例 #2
0
        private static void CountCountUpSequence(int max)
        {
            WriteLine("Count up sequence");

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            var cus = new CountUpSequence(max);
            stopWatch.Stop();
            WriteLine("Time to initialise: " + stopWatch.ElapsedMilliseconds);

            stopWatch.Restart();
            WriteLine(cus.Count());
            stopWatch.Stop();
            WriteLine("Time to count with extension method: " + stopWatch.ElapsedMilliseconds);

            stopWatch.Restart();
            var cusAsList = cus.ToList();
            stopWatch.Stop();
            WriteLine("Time to get list: " + stopWatch.ElapsedMilliseconds);

            stopWatch.Restart();
            WriteLine(cusAsList.Count);
            stopWatch.Stop();
            WriteLine("Time to count with prop from list: " + stopWatch.ElapsedMilliseconds);

            WriteLine();
        }