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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to measure program speed?

How to measure program speed?

Scheduled Pinned Locked Moved C / C++ / MFC
algorithmsperformancehelptutorialquestion
9 Posts 4 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.
  • G Offline
    G Offline
    Grimes
    wrote on last edited by
    #1

    Hi there Can someone please help me. I am looking for a way to measure the speed of my program's execution. I am busy writing a simulation that needs to run as fast as possible and I want to make sure that the algorithms used are the fastest possible. Is there a way or a tool that can be used to measure the speed, like the amount of CPU clock cycles needed to complete an algorithm. thank you in advance. Riaan.

    KOM UIT DAAAAA!!!

    D _ 2 Replies Last reply
    0
    • G Grimes

      Hi there Can someone please help me. I am looking for a way to measure the speed of my program's execution. I am busy writing a simulation that needs to run as fast as possible and I want to make sure that the algorithms used are the fastest possible. Is there a way or a tool that can be used to measure the speed, like the amount of CPU clock cycles needed to complete an algorithm. thank you in advance. Riaan.

      KOM UIT DAAAAA!!!

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Have you tried the profiler that comes with Visual Studio?

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      G 1 Reply Last reply
      0
      • D David Crow

        Have you tried the profiler that comes with Visual Studio?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        G Offline
        G Offline
        Grimes
        wrote on last edited by
        #3

        I am not that familiar with visual studio, but I see there is a reference in the help to the profiler. It seems that it would be able to do what I want. I will look in to the profiler. Thanks for pointing me in the right direction!

        KOM UIT DAAAAA!!!

        1 Reply Last reply
        0
        • G Grimes

          Hi there Can someone please help me. I am looking for a way to measure the speed of my program's execution. I am busy writing a simulation that needs to run as fast as possible and I want to make sure that the algorithms used are the fastest possible. Is there a way or a tool that can be used to measure the speed, like the amount of CPU clock cycles needed to complete an algorithm. thank you in advance. Riaan.

          KOM UIT DAAAAA!!!

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          Not sure if this is what you want but you could use high resolution timer functions like QueryPerformanceCounter/QueryPerformanceFrequency before and after a piece of executing code and compare their values.

          «_Superman_» I love work. It gives me something to do between weekends.
          Microsoft MVP (Visual C++)

          G 1 Reply Last reply
          0
          • _ _Superman_

            Not sure if this is what you want but you could use high resolution timer functions like QueryPerformanceCounter/QueryPerformanceFrequency before and after a piece of executing code and compare their values.

            «_Superman_» I love work. It gives me something to do between weekends.
            Microsoft MVP (Visual C++)

            G Offline
            G Offline
            Grimes
            wrote on last edited by
            #5

            Hi How would one use this?

            QueryFrequencyCounter(Begin)
            ...CODE...
            QueryFrequencyCounter(END)
            TIME = END - BEGIN;

            What is the unit of the counter? milliseconds or microseconds or clock cycles? I will give it a try, thank you!

            KOM UIT DAAAAA!!!

            D M 2 Replies Last reply
            0
            • G Grimes

              Hi How would one use this?

              QueryFrequencyCounter(Begin)
              ...CODE...
              QueryFrequencyCounter(END)
              TIME = END - BEGIN;

              What is the unit of the counter? milliseconds or microseconds or clock cycles? I will give it a try, thank you!

              KOM UIT DAAAAA!!!

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Grimes wrote:

              What is the unit of the counter? milliseconds or microseconds or clock cycles?

              See here and here.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              _ 1 Reply Last reply
              0
              • D David Crow

                Grimes wrote:

                What is the unit of the counter? milliseconds or microseconds or clock cycles?

                See here and here.

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                _ Offline
                _ Offline
                _Superman_
                wrote on last edited by
                #7

                Here is an interesting blog - QueryPerformanceCounter counts elapsed time, not CPU cycles[^]

                «_Superman_» I love work. It gives me something to do between weekends.
                Microsoft MVP (Visual C++)

                1 Reply Last reply
                0
                • G Grimes

                  Hi How would one use this?

                  QueryFrequencyCounter(Begin)
                  ...CODE...
                  QueryFrequencyCounter(END)
                  TIME = END - BEGIN;

                  What is the unit of the counter? milliseconds or microseconds or clock cycles? I will give it a try, thank you!

                  KOM UIT DAAAAA!!!

                  M Offline
                  M Offline
                  Member 4194593
                  wrote on last edited by
                  #8

                  Check the Masm32 forum. In the Laboratory there is a huge amount of information about timing, a Macro to set up the timing, and what it takes to get accurate results.

                  G 1 Reply Last reply
                  0
                  • M Member 4194593

                    Check the Masm32 forum. In the Laboratory there is a huge amount of information about timing, a Macro to set up the timing, and what it takes to get accurate results.

                    G Offline
                    G Offline
                    Grimes
                    wrote on last edited by
                    #9

                    Thanks!!! That counter macro seems to be counting the CPU cycles for a block of code. That does seem like the best way of determining the efficiency of a block of code, unlike time, that can vary greatly on different machines. thanks for the help!

                    KOM UIT DAAAAA!!!

                    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