开发者

How can the slow steps of a moderately fast process be found?

开发者 https://www.devze.com 2023-03-18 04:30 出处:网络
I have a windows forms application. When 开发者_Go百科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

I have a windows forms application. When 开发者_Go百科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?


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


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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消