0

I have a windows forms application. When a user selects an item to view the details of, it takes upwards of 4 seconds to load the detail screen (average is 2.5). This seems like it's way too long...and yet it's not THAT long.

The problem I have with this is that it is hard to track down because it's longer than it should be but not too long. In other words, if it was taking 30 seconds, I could easily step through and find the steps that were taking up that time. But with 4 seconds, you run into things like the debugger is slowing it down, so you don't know for sure if you have found the slow step.

How can I track down the slow steps in a moderately "fast" process?

richard
  • 12,263
  • 23
  • 95
  • 151

3 Answers3

2

You can use a profiler to tell you where the time is being spent.

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
1

Just record timestamps of major steps of your process into a logfile or to a separate window. Something like that will do:

string times = "";
times += string.Format("step 1: {0}\n", DateTime.Now);

// ...

times += string.Format("step 2: {0}\n", DateTime.Now);

// ...

times += string.Format("step 3: {0}\n", DateTime.Now);

// now output the string to a file or to a different window (or even examine it in the debugger)
Rom
  • 4,129
  • 23
  • 18
  • But doesn't this introduce other bits of code that could interfere with what is really happening? – richard Jul 08 '11 at 22:12
  • If you're measuring latencies in seconds, this method will not skew your numbers by any noticeable value. This method will slow down execution of the function by microseconds, which is 6 (or more) orders of magnitude less than the delays you're trying to measure. Note, that any method (e.g. profiling) will introduce delays, but most of them are going to be small as well – Rom Jul 08 '11 at 22:23
1

A quick and dirty way to find the bottleneck is to start the slow operation, and then immediately "Break All" - by clicking the "Break All" button, or pressing Ctrl+Alt+Break.

When you do this a few times, you'll often find the program breaks in the same place multiple times, which should give a clue as to what is chewing up all the time.

Tom Bushell
  • 5,865
  • 4
  • 45
  • 60