[ACCEPTED]-How to measure C# console application running time?-c#
using System;
using System.Diagnostics;
//Setting a Stopwatch
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < length; i++)
{
//some logic there
}
//Stopping a Stopwatch
sw.Stop();
Console.WriteLine(sw.Elapsed);
//delay
Console.ReadLine();
This is a simple example of using Stopwatch. But 2 don't forget to write "using System.Diagnostics;", otherwise 1 Stopwatch just won't be founded.
What about using the Stopwatch class.
http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx
Particularly 8 notice the note called out on MSDN
On a multiprocessor 7 computer, it does not matter which processor 6 the thread runs on. However, because of 5 bugs in the BIOS or the Hardware Abstraction 4 Layer (HAL), you can get different timing 3 results on different processors. To specify 2 processor affinity for a thread, use the 1 ProcessThread.ProcessorAffinity method.
console application does not close if you 1 write
Console.ReadLine();
You can also get the time at the beginning 2 and at the end of the program, and substract 1 it
http://msdn.microsoft.com/en-us/library/system.datetime.now.aspx
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.