Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Where is my program spending the majority of time?

Where is my program spending the majority of time?

Scheduled Pinned Locked Moved Visual Basic
questiontoolsjsonperformancehelp
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    treddie
    wrote on last edited by
    #1

    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! :)

    D T 2 Replies Last reply
    0
    • T treddie

      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! :)

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      T 1 Reply Last reply
      0
      • D 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 Kreskowiak

        T Offline
        T Offline
        treddie
        wrote on last edited by
        #3

        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?

        D 1 Reply Last reply
        0
        • T treddie

          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?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          T 1 Reply Last reply
          0
          • D 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 Kreskowiak

            T Offline
            T Offline
            treddie
            wrote on last edited by
            #5

            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!

            D 1 Reply Last reply
            0
            • T treddie

              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!

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • T treddie

                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! :)

                T Offline
                T Offline
                Tim Carmichael
                wrote on last edited by
                #7

                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.

                T 1 Reply Last reply
                0
                • T Tim Carmichael

                  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.

                  T Offline
                  T Offline
                  treddie
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups