예제 #1
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();
            long      number    = 999;

            methodsToExamine[] methods = new methodsToExamine[10]
            {
                Persist.Persistence1,
                Persist.Persistence2,
                Persist.Persistence3,
                Persist.Persistence4,
                Persist.Persistence5,
                Persist.Persistence6,
                Persist.Persistence7,
                Persist.Persistence8,
                Persist.Persistence9,
                Persist.Persistence10
            };


            TimeSpan[] timeSpans = new TimeSpan[9];

            foreach (var method in methods)
            {
                Console.WriteLine($"{number}: {method(number)}");
            }

            stopwatch.Start();
            for (int i = 0; i < 1000000; i++)
            {
                Persist.Persistence1(number);
            }
            stopwatch.Stop();
            Console.WriteLine($" 1: {stopwatch.Elapsed}");

            stopwatch.Restart();
            for (int i = 0; i < 1000000; i++)
            {
                Persist.Persistence2(number);
            }
            stopwatch.Stop();
            Console.WriteLine($" 2: {stopwatch.Elapsed}");
            stopwatch.Restart();
            for (int i = 0; i < 1000000; i++)
            {
                Persist.Persistence3(number);
            }
            stopwatch.Stop();
            Console.WriteLine($" 3: {stopwatch.Elapsed}");

            stopwatch.Restart();
            for (int i = 0; i < 1000000; i++)
            {
                Persist.Persistence4(number);
            }
            stopwatch.Stop();
            Console.WriteLine($" 4: {stopwatch.Elapsed}");

            stopwatch.Restart();
            for (int i = 0; i < 1000000; i++)
            {
                Persist.Persistence5(number);
            }
            stopwatch.Stop();
            Console.WriteLine($" 5: {stopwatch.Elapsed}");

            stopwatch.Restart();
            for (int i = 0; i < 1000000; i++)
            {
                Persist.Persistence6(number);
            }
            stopwatch.Stop();
            Console.WriteLine($" 6: {stopwatch.Elapsed}");

            stopwatch.Restart();
            for (int i = 0; i < 1000000; i++)
            {
                Persist.Persistence7(number);
            }
            stopwatch.Stop();
            Console.WriteLine($" 7: {stopwatch.Elapsed}");

            stopwatch.Restart();
            for (int i = 0; i < 1000000; i++)
            {
                Persist.Persistence8(number);
            }
            stopwatch.Stop();
            Console.WriteLine($" 8: {stopwatch.Elapsed}");

            stopwatch.Restart();
            for (int i = 0; i < 1000000; i++)
            {
                Persist.Persistence9(number);
            }
            stopwatch.Stop();
            Console.WriteLine($" 9: {stopwatch.Elapsed}");

            stopwatch.Restart();
            for (int i = 0; i < 1000000; i++)
            {
                Persist.Persistence10(number);
            }
            stopwatch.Stop();
            Console.WriteLine($"10: {stopwatch.Elapsed}");

            Console.ReadKey();
        }