Optimize Process Speed using C#

To optimized code speed you can use System.Diagnostics Namespace.

=============================

using System;
using System.Diagnostics;
using System.Threading;

namespace DiagnoseProcessSpeed
{
    internal class Program
    {
        static void Main()
        {
            Stopwatch sw = Stopwatch.StartNew(); // Start Stopwatch
            for (int i = 1; i < 11; i++)
            {
                System.Console.WriteLine("Loop : " + i);
                Thread.Sleep(1000);// interval for 1 seconds.
            }
            sw.Stop(); // End Stopwatch

            //sw.Elapsed Contain Process Taking Time in Seconds
            System.Console.WriteLine("Total Taking Time: " + sw.Elapsed + "(In Seconds)");
            Console.ReadKey();
        }
    }
}


============================

Result: 

Loop : 1
Loop : 2
Loop : 3
Loop : 4
Loop : 5
Loop : 6
Loop : 7
Loop : 8
Loop : 9
Loop : 10
Total Taking Time: 00:00:10.1165235(In Seconds)
  






Comments

Popular posts from this blog

Tree view in winforms using c#

how to Replace null value with 0 Using C#

how to fetch all HTML Table Records and modify all records accordingly using jquery and Javascript