+ Reply to Thread
Results 1 to 2 of 2

Thread: Measure elapsed time for a given function call

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    3

    Measure elapsed time for a given function call

    How can I accurately measure elapsed time for a given function call?

  2. #2
    Junior Member
    Join Date
    Oct 2012
    Posts
    7
    Stopwatch is a class in the .NET Framework that is ideal for timing any operation in your C# programs. It is found in System.Diagnostics namespace.

    Example:
    Code:
    static void Main()
    {
    	// Create new stopwatch
    	Stopwatch stopwatch = new Stopwatch();
    
    	// Begin timing
    	stopwatch.Start();
    
    	// Do something
    	for (int i = 0; i < 1000; i++)
    	{
    	    Thread.Sleep(1);
    	}
    
    	// Stop timing
    	stopwatch.Stop();
    
    	// Write result
    	Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
    }

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts