Sunday, July 14, 2013

Make a Timespan to inspect the duration of a code loop?

DateTime beforeProcess = DateTime.Now;
//imagine a LINQ process here
DateTime afterProcess = DateTime.Now;
TimeSpan duration = afterProcess.Subtract(beforeProcess);
//imagine setting a breakpoint here to inspect duration

 
 

This touches on the Timespan type some. In setting a breakpoint one could inspect the Timespan and see how many milliseconds an execution took. Something that might be easier to read is:

long duration = (afterProcess - beforeProcess).Ticks;

 
 

It is really up to you. Run a code loop a couple of times and you may see different results with the timing getting faster for a few times until it finds a "floor."

No comments:

Post a Comment