Where is my program spending the majority of time?
-
Hi all. I have a question about program performance. I have a ton of loops all over the place, and a pause button to pause execution. The pause button is pretty much useless right now as it gets superceded by what I figure are long-winded loops. In an attempt to locate the problem loops, I ended up placing temporary DoEvents lines in all of them. The idea was to see if I could get better performance out of the button. Then, I could remove the majority of those DoEvents that did not impact performance all that much. Unfortunately, all that work resulted in no better performance at all for the button. So I have two questions: 1. Is there some utility that can pinpoint where the majority of a program spends its time, without placing timers or stopwatches everywhere. 2. Are their certain events or API functions that can essentially "shut-down" DoEvents lines? Thanks for any advice! :)
-
Hi all. I have a question about program performance. I have a ton of loops all over the place, and a pause button to pause execution. The pause button is pretty much useless right now as it gets superceded by what I figure are long-winded loops. In an attempt to locate the problem loops, I ended up placing temporary DoEvents lines in all of them. The idea was to see if I could get better performance out of the button. Then, I could remove the majority of those DoEvents that did not impact performance all that much. Unfortunately, all that work resulted in no better performance at all for the button. So I have two questions: 1. Is there some utility that can pinpoint where the majority of a program spends its time, without placing timers or stopwatches everywhere. 2. Are their certain events or API functions that can essentially "shut-down" DoEvents lines? Thanks for any advice! :)
DoEvent was never going to get you any performance benefit, and, frankly, we're all looking at you funny for even thinking so. DoEvents stops your code and execute all the messages pending in your apps message pump. Nothing more... What you're looking for is a code profiler. If you have an Ultimate Edition of Visual Studio, it's built in. If not, you'll have to use a third party product, none of which are free.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
DoEvent was never going to get you any performance benefit, and, frankly, we're all looking at you funny for even thinking so. DoEvents stops your code and execute all the messages pending in your apps message pump. Nothing more... What you're looking for is a code profiler. If you have an Ultimate Edition of Visual Studio, it's built in. If not, you'll have to use a third party product, none of which are free.
A guide to posting questions on CodeProject[^]
Dave KreskowiakI'm probably not explaining myself clearly. If you have a long-winded loop somewhere and want to pause execution for some reason, you can't do it with a button click unless you have a DoEvents line in there so that the loop can stop long enough to process system events. By "performance", I meant that the "performance" of the Pause button improves because now it has a chance to be processed in the middle of the loop. I know that DoEvents() slows things down for exactly the reason you point out, but under the circumstances, unless there is an alternative to DoEvents(), I'm stuck. But the other possible explanation of the problem is that somehow, no matter what loops I put my DoEvents lines in, something shuts them down so that they do not respond. Is that likely?
-
I'm probably not explaining myself clearly. If you have a long-winded loop somewhere and want to pause execution for some reason, you can't do it with a button click unless you have a DoEvents line in there so that the loop can stop long enough to process system events. By "performance", I meant that the "performance" of the Pause button improves because now it has a chance to be processed in the middle of the loop. I know that DoEvents() slows things down for exactly the reason you point out, but under the circumstances, unless there is an alternative to DoEvents(), I'm stuck. But the other possible explanation of the problem is that somehow, no matter what loops I put my DoEvents lines in, something shuts them down so that they do not respond. Is that likely?
treddie wrote:
you have a long-winded loop somewhere and want to pause execution for some reason, you can't do it with a button click unless you have a DoEvents line in there
Wrong. The correct technique is to move the long running operation to a background thread. Then you don't need DoEvents (and the headaches that come with it) and just set a flag or some other synchronization object. That way your UI isn't blocked.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
treddie wrote:
you have a long-winded loop somewhere and want to pause execution for some reason, you can't do it with a button click unless you have a DoEvents line in there
Wrong. The correct technique is to move the long running operation to a background thread. Then you don't need DoEvents (and the headaches that come with it) and just set a flag or some other synchronization object. That way your UI isn't blocked.
A guide to posting questions on CodeProject[^]
Dave KreskowiakAh...OK. I need to think parallel these days. :) And thanks for the info on code profilers. I did do a quick search and found a couple of free ones, though I don't know if they are any good, or for that matter, truly "free" (aka fully-functional, non-demo). Thanks for the help. Much appreciated!
-
Ah...OK. I need to think parallel these days. :) And thanks for the info on code profilers. I did do a quick search and found a couple of free ones, though I don't know if they are any good, or for that matter, truly "free" (aka fully-functional, non-demo). Thanks for the help. Much appreciated!
Just make sure you're not using a memory profiler. Those are a bit more common and some of those are free. They're not the same as a code profiler.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Hi all. I have a question about program performance. I have a ton of loops all over the place, and a pause button to pause execution. The pause button is pretty much useless right now as it gets superceded by what I figure are long-winded loops. In an attempt to locate the problem loops, I ended up placing temporary DoEvents lines in all of them. The idea was to see if I could get better performance out of the button. Then, I could remove the majority of those DoEvents that did not impact performance all that much. Unfortunately, all that work resulted in no better performance at all for the button. So I have two questions: 1. Is there some utility that can pinpoint where the majority of a program spends its time, without placing timers or stopwatches everywhere. 2. Are their certain events or API functions that can essentially "shut-down" DoEvents lines? Thanks for any advice! :)
To determine where your code is spending time, consider using some sort of switchable logging. Use a boolean operator to turn logging on/off, or a variable to set the level of desire logging. Then, if logging is enabled, mark in a log the entry and exit time of each routine, each loop, each loop iteration, etc as desired. Is is pretty? No, but if you don't have funds available to purchase a professional product, it provides a solution.
-
To determine where your code is spending time, consider using some sort of switchable logging. Use a boolean operator to turn logging on/off, or a variable to set the level of desire logging. Then, if logging is enabled, mark in a log the entry and exit time of each routine, each loop, each loop iteration, etc as desired. Is is pretty? No, but if you don't have funds available to purchase a professional product, it provides a solution.
Heheh...That's why I didn't want to go that route. It's a lot of work that is for temporary use. Oddly, though, I had already set up a logging system for this program to write to a text file at key points in the code, so that any customers who buy my program could send me that file if they run into any bugs. The only thing missing are the time stamps. So, come to think of it, since it's already in place, it's not such a big deal to add time stamps. As for the two profilers I located: This one is free, but appears tailored to AMD chips: http://developer.amd.com/tools/heterogeneous-computing/amd-codeanalyst-performance-analyzer/ This company has a free version of their product, but didn't have time to check what it's limitations are: http://eqatec.com/Profiler/Download.aspx?BannerId=1&VendorId=1&PortalId=0