Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8706539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:38:19+00:00 2026-06-13T03:38:19+00:00

I need to measure function execution time in nanoseconds. Now I want to understand

  • 0

I need to measure function execution time in nanoseconds. Now I want to understand if my computer can do that and what is the precision of measurement. There was a suggestion to use QueryPerformanceFrequency() to obtain the HPET’s frequency and 1/hpetFrequency is the atomic time that can be measured. Is this right? I mean if my cpu frequency is 3.33 GH, even 1GHz that one clock duration is one nanoseconds. Doesn’t it mean that I can measure by nanoseconds?

For measuring time CPU or HPET’s frequency is essential and why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:38:20+00:00Added an answer on June 13, 2026 at 3:38 am

    You cannot measure to 1 nanosecond, you cannot measure to 10 nanosconds either. This is because each action of measurement requires a call of some kind. One of the fastest APIs is
    GetSystemTimeAsFileTime(). A call requires 10-15ns. But it’s resolution/granularity is rather poor (in the ms regime). QueryPerformanceCounter() delivers frequencies in the MHz to GHz range, depending on the underlaying hardware. This call is not as fast but at 1MHz you get 1 microsecond resolution. At such a frequency, given by QueryPerformanceFrequency(), consecutive call will may return equal values because the call is faster than the increment rate.
    Another source is the CPU time stamp counter (rdtsc). But there are some drawback with it too: Modern hardware implements adpative CPU frequency. Therefore this frequency cannot be considered as a constant. This way measurements are only posible during constant phases.

    In fact none of the frequency sources delivers a constant frequency. All of these frequencies are generated by some hardware which has offset and drift. So the OS will return a value for QueryPerformanceFrequency or CPU frequency and makes you believe it is a constant. However, the number you’ll get are only close estimates.

    Real accurate timing can only be performed when these frequencies are calibrated against the systems RTC. See this publication for more detailed information about accurate timing on windows.

    Edit: Windows chooses the Time Stamp Counter of the cpu. In such cases the result of QPF() equals the processor speed divided by a fixed number (1024 in your case). Windows chooses to built the timekeeping around the TSC with preference when a constant/invariant TSC is available. 3.33 GHz/1024=3.25 MHz.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need measure how time took a scriptblock (remote execution). This is my code:
I need to measure the time it takes for a function to complete in
I need to measure CPU time of a function like following: t <- getCPUTime
I need to measure the time between character events on a serial port, preferably
I have a simple website. Now I need to measure traffic to my website.
For performance tests I need a way to measure the time needed for a
Possible Duplicate: C++ Timer function to provide time in nano seconds I need to
I need a function to run at a precise time within +/- 1ms. I
I have made a file called time.hs . It contains a single function that
I have a SSAS cube in which there is a measure that needs to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.