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

QueryPerformanceCounter

Scheduled Pinned Locked Moved C / C++ / MFC
question
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.
  • C Offline
    C Offline
    Calin Negru
    wrote on last edited by
    #1

    What does QueryPerformanceFrequency measure? units per second?

    Greg UtasG L 2 Replies Last reply
    0
    • C Calin Negru

      What does QueryPerformanceFrequency measure? units per second?

      Greg UtasG Offline
      Greg UtasG Offline
      Greg Utas
      wrote on last edited by
      #2

      Here's how I get the current time (in ticks):

      TimePoint SysTickTimer::Now() const
      {
      if(available_) // previously set based on whether high-frequency timing is available
      {
      LARGE_INTEGER now;
      QueryPerformanceCounter(&now);
      return TimePoint(now.QuadPart); // the current time in ticks (64 bits)
      }
      else // will only have millisecond accuracy
      {
      _timeb now;
      _ftime_s(&now);
      auto msecs = 1000LL * now.time;
      return TimePoint(msecs + now.millitm);
      }
      }

      My Windows 10 installation, running on a Dell XPS15, has 10^7 ticks per second (1 tick = 0.1 usecs). This is determined by

      LARGE_INTEGER frequency;

      if(QueryPerformanceFrequency(&frequency))
      {
      available_ = true;
      ticks_per_sec_ = frequency.QuadPart;
      }

      Robust Services Core | Software Techniques for Lemmings | Articles

      <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
      <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

      C 1 Reply Last reply
      0
      • C Calin Negru

        What does QueryPerformanceFrequency measure? units per second?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        All explained in the documentation: QueryPerformanceFrequency function - Win32 apps | Microsoft Docs[^].

        C 1 Reply Last reply
        0
        • Greg UtasG Greg Utas

          Here's how I get the current time (in ticks):

          TimePoint SysTickTimer::Now() const
          {
          if(available_) // previously set based on whether high-frequency timing is available
          {
          LARGE_INTEGER now;
          QueryPerformanceCounter(&now);
          return TimePoint(now.QuadPart); // the current time in ticks (64 bits)
          }
          else // will only have millisecond accuracy
          {
          _timeb now;
          _ftime_s(&now);
          auto msecs = 1000LL * now.time;
          return TimePoint(msecs + now.millitm);
          }
          }

          My Windows 10 installation, running on a Dell XPS15, has 10^7 ticks per second (1 tick = 0.1 usecs). This is determined by

          LARGE_INTEGER frequency;

          if(QueryPerformanceFrequency(&frequency))
          {
          available_ = true;
          ticks_per_sec_ = frequency.QuadPart;
          }

          Robust Services Core | Software Techniques for Lemmings | Articles

          C Offline
          C Offline
          Calin Negru
          wrote on last edited by
          #4

          it`s ticks per second. Thanks Greg for showing how you handle it.

          1 Reply Last reply
          0
          • L Lost User

            All explained in the documentation: QueryPerformanceFrequency function - Win32 apps | Microsoft Docs[^].

            C Offline
            C Offline
            Calin Negru
            wrote on last edited by
            #5

            thanks, I got it working.

            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