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. C / C++ / MFC
  4. How to get execution time of a function in microsecs?

How to get execution time of a function in microsecs?

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
5 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.
  • S Offline
    S Offline
    shir_k
    wrote on last edited by
    #1

    Hi, I want to measure elapsed time of a function in microsecs how to do that. I tried with clock()(output is in seconds/ millisec),GetTickCount() (in millisec) the output is in secs or millisecs,i need in microsecs.Is there any function in VC++? Thanks

    T J 2 Replies Last reply
    0
    • S shir_k

      Hi, I want to measure elapsed time of a function in microsecs how to do that. I tried with clock()(output is in seconds/ millisec),GetTickCount() (in millisec) the output is in secs or millisecs,i need in microsecs.Is there any function in VC++? Thanks

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #2

      shir_k wrote:

      I tried with clock()(output is in seconds/ millisec),GetTickCount() (in millisec) the output is in secs or millisecs,i need in microsecs.Is there any function in VC++?

      try QueryPerformanceCounter (Multimedia Timers)

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
      Never mind - my own stupidity is the source of every "problem" - Mixture

      cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

      J 1 Reply Last reply
      0
      • T ThatsAlok

        shir_k wrote:

        I tried with clock()(output is in seconds/ millisec),GetTickCount() (in millisec) the output is in secs or millisecs,i need in microsecs.Is there any function in VC++?

        try QueryPerformanceCounter (Multimedia Timers)

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
        Never mind - my own stupidity is the source of every "problem" - Mixture

        cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

        J Offline
        J Offline
        James R Twine
        wrote on last edited by
        #3

        Not without calling QueryPerformanceFrequency(...) first to make sure that [1] the HR timer is available and [2] that it supports microsecond-level resolution...    Peace!

        -=- James
        Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        See DeleteFXPFiles

        T 1 Reply Last reply
        0
        • S shir_k

          Hi, I want to measure elapsed time of a function in microsecs how to do that. I tried with clock()(output is in seconds/ millisec),GetTickCount() (in millisec) the output is in secs or millisecs,i need in microsecs.Is there any function in VC++? Thanks

          J Offline
          J Offline
          James R Twine
          wrote on last edited by
          #4

          You may also be able to get suitable timing information using the RDTSC instruction.  Google for it for more details.  If the function will not be running across multiple physical or logical CPUs (its affinity is locked to one CPU, or it is running in a single-CPU system), and will not be running across a sleep/hybernation operation, it should be accurate enough.    Peace!

          -=- James
          Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
          Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
          See DeleteFXPFiles

          1 Reply Last reply
          0
          • J James R Twine

            Not without calling QueryPerformanceFrequency(...) first to make sure that [1] the HR timer is available and [2] that it supports microsecond-level resolution...    Peace!

            -=- James
            Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
            Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
            See DeleteFXPFiles

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

            James R. Twine wrote:

            first to make sure that [1] the HR timer is available and [2] that it supports microsecond-level resolution...

            right as usual :)

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
            Never mind - my own stupidity is the source of every "problem" - Mixture

            cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

            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