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. timer

timer

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
6 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.
  • J Offline
    J Offline
    Jerome Conus
    wrote on last edited by
    #1

    Hi ! I need to check in a C++ app, as precisely as possible, the time spent by the processor in a function. I have no idea where to start ! Any help will be greatly appreciated ! Jerome

    J H 2 Replies Last reply
    0
    • J Jerome Conus

      Hi ! I need to check in a C++ app, as precisely as possible, the time spent by the processor in a function. I have no idea where to start ! Any help will be greatly appreciated ! Jerome

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      If you have access to the source code of the program, and the version of your Visual Studio installation is Professional or Enterprise, then you can do a profiling of your code, which gives you more or less accurate summaries of the time spent by the program in each function. You can start learning about profiling in Visual Studio with Cornell University tutorial Profiling with MS Visual Studio Tools. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      1 Reply Last reply
      0
      • J Jerome Conus

        Hi ! I need to check in a C++ app, as precisely as possible, the time spent by the processor in a function. I have no idea where to start ! Any help will be greatly appreciated ! Jerome

        H Offline
        H Offline
        HintiFlo
        wrote on last edited by
        #3

        Hi Jerome. Here's a simple class, it's not my idea, unfortunately I don't know whose copyright it is, I think it's from somwhere at CP: #pragma once class CDuration { protected: LARGE_INTEGER m_liStart; LARGE_INTEGER m_liStop; LONGLONG m_llFrequency; LONGLONG m_llCorrection; public: CDuration(void); void Start(void); void Stop(void); long GetDuration(void) const; }; inline CDuration::CDuration(void) { LARGE_INTEGER liFrequency; QueryPerformanceFrequency(&liFrequency); m_llFrequency = liFrequency.QuadPart; // Calibration Start(); Stop(); m_llCorrection = m_liStop.QuadPart-m_liStart.QuadPart; } inline void CDuration::Start(void) { // Ensure we will not be interrupted by any other thread for a while Sleep(0); QueryPerformanceCounter(&m_liStart);} inline void CDuration::Stop(void) {QueryPerformanceCounter(&m_liStop);} inline long CDuration::GetDuration(void) const { return (long)(m_liStop.QuadPart-m_liStart.QuadPart-m_llCorrection)*1000000.0 / m_llFrequency;} usage e.g.: CDuration durat; durat.Start(); FunctionCallToMeasure(); durat.Stop(); long ms_needed = durat.GetDuration(); I think the GetDuration return gives the time in milliseconds. I try to find the docu, then I can tell you more! Good Luck, Flo

        J 1 Reply Last reply
        0
        • H HintiFlo

          Hi Jerome. Here's a simple class, it's not my idea, unfortunately I don't know whose copyright it is, I think it's from somwhere at CP: #pragma once class CDuration { protected: LARGE_INTEGER m_liStart; LARGE_INTEGER m_liStop; LONGLONG m_llFrequency; LONGLONG m_llCorrection; public: CDuration(void); void Start(void); void Stop(void); long GetDuration(void) const; }; inline CDuration::CDuration(void) { LARGE_INTEGER liFrequency; QueryPerformanceFrequency(&liFrequency); m_llFrequency = liFrequency.QuadPart; // Calibration Start(); Stop(); m_llCorrection = m_liStop.QuadPart-m_liStart.QuadPart; } inline void CDuration::Start(void) { // Ensure we will not be interrupted by any other thread for a while Sleep(0); QueryPerformanceCounter(&m_liStart);} inline void CDuration::Stop(void) {QueryPerformanceCounter(&m_liStop);} inline long CDuration::GetDuration(void) const { return (long)(m_liStop.QuadPart-m_liStart.QuadPart-m_llCorrection)*1000000.0 / m_llFrequency;} usage e.g.: CDuration durat; durat.Start(); FunctionCallToMeasure(); durat.Stop(); long ms_needed = durat.GetDuration(); I think the GetDuration return gives the time in milliseconds. I try to find the docu, then I can tell you more! Good Luck, Flo

          J Offline
          J Offline
          Jerome Conus
          wrote on last edited by
          #4

          Thank you a lot for your help ! Jerome

          H 1 Reply Last reply
          0
          • J Jerome Conus

            Thank you a lot for your help ! Jerome

            H Offline
            H Offline
            HintiFlo
            wrote on last edited by
            #5

            Hi Jerome there you find the article, source and demo: http://www.codeproject.com/cpp/duration.asp what is your app made for? mfg HintiFlo

            J 1 Reply Last reply
            0
            • H HintiFlo

              Hi Jerome there you find the article, source and demo: http://www.codeproject.com/cpp/duration.asp what is your app made for? mfg HintiFlo

              J Offline
              J Offline
              Jerome Conus
              wrote on last edited by
              #6

              Thank you for the information ! I'm working on a real-time App, which controls a machine, but we're having problems reaching the required speed of the machine. Thus, I wanted to check where, in the software, we are loosing time ! It's not easy !!! Tanks again and best regards, (or mfg, should I say !!!;-) ) Jerome

              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