[ACCEPTED]-How to measure C# console application running time?-c#

Accepted answer
Score: 11

Set up a Stopwatch at initialisation and check its 1 Elapsed property at exit.

Score: 6
        using System;
        using System.Diagnostics;
            //Setting a Stopwatch 
            Stopwatch sw = new Stopwatch();
            for (int i = 0; i < length; i++)
                //some logic there
            //Stopping a Stopwatch


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.

Score: 3

What about using the Stopwatch class.


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.

Score: 1

console application does not close if you 1 write

Score: 0

You can also get the time at the beginning 2 and at the end of the program, and substract 1 it


More Related questions