What is best way to measure the time cycles for a C# function ?

Posted by Duaa on Stack Overflow See other posts from Stack Overflow or by Duaa
Published on 2011-01-11T02:37:13Z Indexed on 2011/01/11 2:53 UTC
Read the original article Hit count: 165

Filed under:

Hi all:

Really, I'm looking for a good function that measure the time cycles accurately for a given C# function under Windows operating system. I tried these functions, but they both do not get accurate measure:

DateTime StartTime = DateTime.Now;      
TimeSpan ts = DateTime.Now.Subtract(StartTime);
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed; 

Really, each time I call them, they give me different time for the same function

Please, if anyone know better way to measure time consuming accurately, please help me and thanks alot alot

© Stack Overflow or respective owner

Related posts about c#