Wrong time displayed

Code profiling for .NET developers.

Moderator: dom.smith

Wrong time displayed

Postby BrcSen » Fri Jan 17, 2014 1:30 pm

Hi
Im trying to profile some code in a backgroundworker (wpf application, .net 4.0 Client Profile). The pseudocode is:
Code: Select all
void bw_DoWork(object sender, DoWorkEventArgs e)
{
    var stopWatch = Stopwatch.StartNew();
   
     // slow running code
    ...

    stopWatch.Stop();
    Debug.WriteLine(\"Time taken: \"+stopWatch.ElapsedMilliseconds+\" ms\");   
}


My stopWatch prints out: \"Time taken: 119823 ms\", but the profiler displays the following values for \"Time With Children\" (bw_DoWork)

CPU time + Miliseconds : 26.524,787
Wallclock time + miliseconds: 48.699,648

Do you know why I get such a big difference? I could understand if profiled time was greater than the stopwatch due to overhead when creating the thread ect, but how come it is less?
BrcSen
 
Posts: 2
Joined: Fri Jan 17, 2014 1:17 pm

Postby Chris.Allen » Mon Jan 20, 2014 7:07 pm

Was this in sampling mode? Sometimes, when sampling mode doesn't have enough data points it can result in an underestimate.
Chris.Allen
 
Posts: 594
Joined: Thu Mar 12, 2009 4:17 pm

Postby BrcSen » Tue Jan 21, 2014 8:48 am

I just tried to select Async Mode under View before pressing executing the code I was trying to profile. This gives the result:

Stopwatch: 458056ms
Wall Time: 442265ms
CPU Time: 372429ms

The wall-clock time is much more accurate now, thanks :)
When should I use async vs sampling?
BrcSen
 
Posts: 2
Joined: Fri Jan 17, 2014 1:17 pm

Postby Chris.Allen » Tue Jan 21, 2014 1:34 pm

Sampling is the mode of choice for longer running projects or projects with a very high degree of CPU usage. The Async feature is really designed to work with the new async keyword. It's great news that you're getting better data now :)
Chris.Allen
 
Posts: 594
Joined: Thu Mar 12, 2009 4:17 pm


Return to ANTS Performance Profiler 8

Who is online

Users browsing this forum: No registered users and 0 guests