J
J
jil2011-11-16 04:37:37
.NET
jil, 2011-11-16 04:37:37

Measuring spans of time in .NET

Faced with the task of measuring the execution time of web methods (for SAS). You need to keep a log. Simple ticking often gives similar (small) values ​​for methods. Advise good ways to measure time. There are many calls, but all are not “heavy”, asynchronously.

Now:

long ticksStart = DateTime.Now.Ticks;
// CALL
TicksTotal = DateTime.Now.Ticks - ticksStart;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AlexSuslin, 2011-12-22
@AlexSuslin

DateTime start = DateTime.Now;

// CALL

DateTime finish = DateTime.Now;

TimeSpan elapsed = new TimeSpan(start.Ticks - finish.Ticks);

And already in elapsed there are TotalSeconds and TotalMilliseconds and other formatting you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question