Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out how many Milliseconds a C# program has taken to execute in your debugger

Tags:

performance

c#

I need to analyze the Performance overhead of my programmed logic using C# debugger. So I need to compare two logics in my code. I dont want to install any add-ons like Analyze into my VisualStudio. I want to analyze the module by writing special functions. Do we have any such predefined functions available in C# ? I need all the options available for testing a module for being GOOD(by good i mean it takes shortest time to execute) FYI I use VisualStudio 2010 Professional edition.

like image 711
LetsKickSomeAss in .net Avatar asked Dec 27 '11 09:12

LetsKickSomeAss in .net


People also ask

How do you count in milliseconds?

To convert a second measurement to a millisecond measurement, multiply the time by the conversion ratio. The time in milliseconds is equal to the seconds multiplied by 1,000.

How much is a 1 millisecond?

A millisecond (from milli- and second; symbol: ms) is one thousandth (0.001 or 10−3 or 1/1000) of a second.

Does Unix timestamp have milliseconds?

Bookmark this question. Show activity on this post. I have a list of unix timestamps that all contain milliseconds -- they are 13 digits long.


1 Answers

If you just want to measure the time a function needs to execute, you can use the Stopwatch class.

Sample:

Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
CallYourFunction();
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
like image 152
Jan Avatar answered Oct 04 '22 01:10

Jan