How to calculate the run time/time required for a program in visual studio or in C Sharp

I recently started programming in C# and I found it far better than Java already. To find the time took by your code , you will have to insert the below snippet . For more information, you can go to the msdn link.

/* importing the lib*/
using System.Diagnostics;


/* creating the object of Stopwatch, where we can it to calculate the time*/
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();// Start the time
stopwatch.Stop();// Stop the time
TimeSpan ts = stopwatch.Elapsed;
            long elapsedMilliseconds;
            elapsedMilliseconds = stopwatch.ElapsedMilliseconds;

/*Conversion of elapsed time to milliseconds. We can even convert it in to minutes or hours. For more information please check the below link to msdn*/


Console.WriteLine("RunTime " + elapsedMilliseconds);

Comments

Popular posts from this blog

How To Install LEX and YACC in Linux or Ubuntu

Lex Program To Check The Syntax of For Loop

How to Implement Two - Pass Assembler in C / Assembler C Code